sql to linq RRS feed

  • Question

  • User-1129879462 posted

    select p.PracticeIdRoot,pd.DescriptionRoot,SUM(wa.Hours) from WorkAllocation as wa
    join Task as p on wa.PracticeIdRoot = p.PracticeIdRoot
    join Task as pd on pd.DescriptionRoot = p.DescriptionRoot
    where wa.Type='E' and wa.ProjectID=101
    group by p.practiceidroot,pd.DescriptionRoot

    How can I convert this SQL query into LINQ?

    Friday, August 2, 2019 5:33 AM

All replies

  • User-1174608757 posted

    Hi krisrajz,

    According to your description you could write as below:

    var query = from wa in db.WorkAllocation
                            join p in db.Task on wa.PracticeIdRoot equals p.PracticeIdRoot
                            join pd in db.Task on wa.DescriptionRoot equals pd.DescriptionRoot
                            where wa.Type == "E" && wa.ProjectID == 101
                            group new { p, pd, wa } by new { p.PracticeIdRoot, pd.DescriptionRoot } into NewDataGroup
                            select new
                                PracticeIdRoot = NewDataGroup.First().p.PracticeIdRoot,
                                DescriptionRoot = NewDataGroup.First().pd.DescriptionRoot,
                                hoursTotal = NewDataGroup.Sum(x => x.wa.Hours).ToString(),

    Else I suggest that you could use sql to linq tool such as linqer.Here is the link ,I hope it could help you.


    Best Regards


    Monday, August 5, 2019 9:36 AM