How to create LINQ to SQL Group by with condition?
How can I create LINQ to SQL request where I can use group by with condition?
For example:
from ri in resItems
group ri by new {groupByPackaging ? (ri.Model, ri.Condition, ri.Packaging) : (ri.Model, ri.Condition)}
into g开发者_StackOverflow
select new
{
...
}
I think this is what your looking for LINQ Conditional Group
Here's an example:
bool someFlag = false;
var result = from t in tableName
group t by new { FieldA = (someFlag ? 0 : t.FieldA), t.FieldB } into g
select g;
精彩评论