I'm trying to do a group by in LINQ to SQL but I want to base the grouping on the text description of my ENUM items.
var qry = from s in _db.Complaints
where s.Site.SiteDescription.Contains(searchTextSite)
&& (s.Raised >= startDate &a开发者_Go百科mp;& s.Raised <= endDate)
group s by s.ComplaintNatureTypeId.ToDescription()
into grp
select new
{
Site = grp.Key,
Count = grp.Count()
};
I'm thinking this must be supported since its very fundamental and think i'm missing something simple.
Anyone any ideas on how i'm getting runtime error & how to remedy this
thanks in advance
Linq to Sql is translated to Sql query so everything must be convertable to query. You can not group items by something that is only in your code. If u want to group by enum you can use ints its unique as your string enums.
精彩评论