LINQ Left Outer Join with Group By and Count Producing Error
I'm constructing a LINQ query expression in LINQPad that uses a left outer join, group by and count. The query is producing the following error.
'AnonymousType#1' does not contain a definition for 'ContentTypeID' and no extension method 'ContentTypeID' accepting a first argument of type 'AnonymousType#1' could be found开发者_如何学JAVA (press F4 to add a using directive or assembly reference)
Here is the query.
from t1 in ContentTypes
from t2 in VwContentTRIGOF.Where(x => t1.ContentTypeID == x.ContentTypeID && new List<int> { 2588, 2227 }.Contains(x.ResearchAreaID)).DefaultIfEmpty()
where t1.IsActive == true
group new {t1, t2} by new { t1.ContentTypeID, t1.Label } into g
select new { g.Key.ContentTypeID, g.Key.Label, Disabled = g.Count(t => t.ContentTypeID == null) > 0 }
The error highlights the last use of ContentTypeID in the last line, but I can't seem to arrange the query to get the desired result.
Any suggestions?
Thank you.
Each item of your group has entries t1
and t2
, not ContentTypeID
, so I suspect your final select
should be:
select new { g.Key.ContentTypeID, g.Key.Label,
Disabled = g.Count(t => t.t2.ContentTypeID == null) > 0 }
(That's assuming you want it from t2
- if you want it from t1
then change it appropriately... but given that t1.ContentTypeID
is part of the key, that seems unlikely... the count would just be the group count.)
精彩评论