jueves, 26 de diciembre de 2013

LINQ Examples


 Example 1

listProjectPersonDO  is a List<ClsRelProjectPersonDO>

foreach (ClsRelProjectPersonDO clsRelProjectPersonDO in 
            listProjectPersonDO.Where(element => element.IdProjectDomainSubdomain == row))
            {


             }


 Example2

 GeneralReport is a DataTable

 var qWorkingArea = GeneralReport.AsEnumerable()
             .GroupBy(r => r.Field<String>("workingArea"))
            .Select(g => new
            {
                totalW = g.Count(),
                workingArea = g.Key,

                onBoardW = ((from c in g where c["status"].ToString() == "ON BOARD" select c).Count())

              })
            .OrderBy(x => x.workingArea);


varGetTotalWorkingAreasOB = qWorkingArea.Sum(x => x.onBoardW); 


Example 3

How to do many selects.
 
var result = pyramid.Select(element => element.ClsRelProjectPersonDO.Where(item => item.IdProjectPerson == 
idProjectPerson)).First();

IEnumerable<ClsRelProjectPersonDO> a = result;

No hay comentarios:

Publicar un comentario