KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to translate the following LINQ query to Dynamic LINQ that accepts several grouping columns based on user input. Basically I have a bunch of dropdownlists that apply groupings and I don't want to enumerate every combination of groupings. If Dynamic LINQ fails, I may have to construct a SQL query manually, and nobody wants that. var grouping = ( from entry in ObjectContext.OmniturePageModules where entry.StartOfWeek >= startDate && entry.StartOfWeek <= endDate && ( section == "Total" || section == "All" || entry.Section == section ) && ( page == "Total" || page == "All" || entry.Page == page ) && ( module == "Total" || module == "All" || entry.Module == module ) group entry by new { entry.Page, // I want to be able to tell this anonymous type entry.Module, // which columns to group by entry.StartOfWeek // at runtime } into entryGroup select new { SeriesName = section + ":" + entryGroup.Key.Page + ":" + entryGroup.Key.Module, Week = entryGroup.Key.StartOfWeek, Clicks = entryGroup.Sum( p => p.Clicks ) } ); I have no clue how to do this as Dynamic LINQ is totally undocumented outside of the "hello world!" select/where/orderby cases. I just can't figure out the syntax. Something like:(?) var grouping = ObjectContext.OmniturePageModules.Where(entry => entry.StartOfWeek >= startDate && entry.StartOfWeek <= endDate && ( section == "Total" || section == "All" || entry.Section == section ) && ( page == "Total" || page == "All" || entry.Page == page ) && ( module == "Total" || module == "All" || entry.Module == module )) .GroupBy("new (StartOfWeek,Page,Mod
Tags (comma-separated)
Save Edits
Cancel