tags:

views:

38

answers:

1

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
        select new
        {
            ...
        }
+2  A: 

I think this is what your looking for http://stackoverflow.com/questions/756827/linq-conditional-group

There 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;
Gage