c# - Linq Group by Week Number Including 0 Record Weeks -



c# - Linq Group by Week Number Including 0 Record Weeks -

i'm trying dataset ssrs line chart. trying show number of records per week of year lastly 6 months. in order line chart accurate, have show weeks have 0 records.

i want provide line chart info looks this:

year week count 2014 52 13 2015 1 0 2015 2 16

the next linq query gets need minus weeks have 0 records:

list = (from t in context.cats.where( t => t.name == "fluffy" && (t.recorded >= start && t.recorded <= end) ).asenumerable() grouping t new { year = t.recorded.year, weeknumber = (t.recorded - new datetime(t.recorded.year, 1, 1)).days / 7 } ut select new trendrecord { year = ut.key.year, week = ut.key.weeknumber, count = ut.count() }).orderby(t => t.year).thenby(t => t.week).tolist<trendrecord>();

i've looked @ this , this questions neither seems quite fit predicament.

i'm leaning towards creating list possible week numbers between start , end dates , left joining info somehow weeks 0 records show up.

is acceptable approach problem(please show me how if so)? there way in 1 query without need separate list bring together to?

you need list of weeks , kind of left outer bring together using linq.

something should help started

var weeks = new[] { new {year = 2014, week = 52}, new {year = 2015, week = 1}, new {year = 2015, week = 2}, }; var listwithemptyweeksincluded = w in weeks l in list.where(x => x.year == w.year && x.week == w.week).defaultifempty() select new trendrecord { year = w.year, week = w.week, count = l == null ? 0 : l.count };

of course, weeks should generated on basis of variables start , end

also, should using standard week calculation, instance iso week standard, weeks span 2 years handled correctly.

c# linq reporting-services

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -