locked
How to construct Nested LINQ RRS feed

  • Question

  • User264732274 posted

    anyone would help me to construct sample linq query which would be similar like below sql query.

    SELECT EmployeeName,

    (Select count(*) from table1 where condition) as data1,

    (Select count(*) from table1 where condition) as data2,

    (Select count(*) from table1 where condition) as data3

    Monday, June 15, 2015 3:35 PM

All replies

  • User61956409 posted

    Hi sudip_inn,

    Thanks for your post.

    Please refer to the following code to convert your SQL statements to LINQ.

    var query = (from ss in entities.ChartInfoes
                    where ss.Id==3
                    select new
                    {
                        Name = ss.Name,
                        //modify the code with .Where(yourcondition)
                        data1 = entities.ChartInfoes.Where(cc => cc.Name == "MAY").Count(),
                        data2 = entities.ChartInfoes.Where(cc => cc.Id == 3).Count(),
                        data3 = entities.ChartInfoes.Where(cc => cc.Id > 0).Count()
                    }).ToList();
    

    Best Regards,

    Fei Han

    Tuesday, June 16, 2015 4:27 AM