开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜