sql - Linq Query with Count aggregate, Group By, and Having statements -


i can simple linq queries , understand "having" clause in sql put clause in linq, because has join , group aggregate "count", can't seem find on simple google search. need sql query in linq syntax. i'm on dot net version 4.5, if helps.

i suppose i'd prefer query syntax, wouldn't mind learning method syntax.

select t1.t1_id, t1.imagecount, count(t2.t1_id_foreignkey) recordsinb t1 left join t2 on t2.t1_id_foreignkey = t1.t1_id group t1.t1_id, t1.imagecount having t1.imagecount = count(t2.t1_id_foreignkey) 

here's attempt, seem have gotten backward or something... should return records in t1 imagecount column 0 , there no records in t2 (equals 0 also). below attempt appears giving me distinct values t2...

from t1 in _db.t1 join t2 in _db.imagerecords on a.t1_id equals b.t1_id_foreignkey group t1 new { t1.t1_id, t1.imagecount } grp grp.key.imagecount == grp.count() select grp.key.t1_id 

any appreciated


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -