c# - LINQ - Join 2 tables, Group by DateTime.Month , multiple Counts -


i'm pretty new c# , linq , i'm trying list of emails holds sum of emails, attachments , user's (the one's sent email).

so current problem output of query false. number of email's equal number of attachment's obvious wrong. query:

var monthquery = em in dbedoka.email                           join ema in dbedoka.email_attachment on em.id equals ema.email_id e                           e2 in e.defaultifempty()                           group e2 em.erstellt_am.month grouped                           select new entities.month                           {                               nameofmonth = grouped.firstordefault().erstellt_am.tostring(),                               numberofmails = grouped.distinct().count(m => m.email_id != null).tostring(),                               numberofattachments = grouped.count(a => a.id != null).tostring(),                               numberofusers = grouped.select(u => u.erstellt_von).distinct().count().tostring()                           };           months = monthquery.tolist();         months = collectionviewsource.getdefaultview(months); 

as can see had take m.email_id dbedoka.email_attachment instead of m.id dbedoka.email because wasn't avaliable (don't know why...). yet have count "numberofmails", "numberofattachments" , "numberofusers".

thank you!


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -