join query with group and condition
-
I want to execute following sql using linq in c# select sum(EDAmount) from accounts a inner join entriesdetail ed on a.Acode =ed.acode inner join entries e on ed.eid = e.eid and e.edate > '1/1/2009' group by ed.acode Following are the entities Accounts - ACode Entry - EID - EDate EntryDetail - EDID - EID - EDAmound - ACode
-
I want to execute following sql using linq in c# select sum(EDAmount) from accounts a inner join entriesdetail ed on a.Acode =ed.acode inner join entries e on ed.eid = e.eid and e.edate > '1/1/2009' group by ed.acode Following are the entities Accounts - ACode Entry - EID - EDate EntryDetail - EDID - EID - EDAmound - ACode
Try this.
var sumEDA =
from a in context.accounts
join ed in context.entriesdetail on a.Acode equals ed.acode
join e in context.entries on ed.eid equals e.eid
where e.edate > Convert.ToDateTime("1/1/2009")
group g by ed.acode
select new { g.Sum(ed.EDAmount) }; -
I want to execute following sql using linq in c# select sum(EDAmount) from accounts a inner join entriesdetail ed on a.Acode =ed.acode inner join entries e on ed.eid = e.eid and e.edate > '1/1/2009' group by ed.acode Following are the entities Accounts - ACode Entry - EID - EDate EntryDetail - EDID - EID - EDAmound - ACode
from a in Accounts join ed in EntryDetail on a.ACODE equals ed.ACODE join e in Entry on e.EID equals ed.EID where e.EDATE > DateTime.Parse("1/1/1990") group ed by ed.ACODE into g select new { g.Group.Sum(s => s.EDAMOUNT) }; Please vote me :)
Niladri Biswas