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 (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
t1andt2, notContentTypeID, so I suspect your finalselectshould be:(That’s assuming you want it from
t2– if you want it fromt1then change it appropriately… but given thatt1.ContentTypeIDis part of the key, that seems unlikely… the count would just be the group count.)