c# - Converting LINQ query to Dynamic Linq -


i have function looks this:

public void getavailableresourcesbylocationchart(list<datetime> dates, list<chartresourcemodel> data) {     var totals = (from r in data                   group new { dates = r.dates } r.location g                   select new                   {                       location = g.key,                       dates = dates.select(d => new                       {                           date = d,                           available = g.selectmany(x => x.dates.where(y => y.date == d)).count(x => x.available)                       })                       .orderby(x => x.date)                       .tolist()                   })                  .orderby(x => x.location)                  .tolist();  } 

this example groups data based on location. want able pass in string specifies should group on. thinking dynamiclinq right way go i'm having trouble reproducing it.

i started off doing this, getting stuck reproducing selectmany inside select:

public void getavailableresourcesbylocationchart(list<datetime> dates, list<chartresourcemodel> data, string grouping) {     var totals = data.groupby(grouping, "it").select("new (it.key group, dates)").cast<dynamic>(); } 

any ideas on need next?

this

   r in data    group new { dates = r.dates } r.location g    ... 

is same this

   data.groupby(r => r.location, b => b.dates) 

so if have variable named grouper

   data.groupby(r => {       if (grouper == "l")          return r.location        else         return r.dates }, b => b.dates); 

this should on right track?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -