Reputation: 232
I have writed linq EF4 query, but it failed with exception The argument to "DbIsNullExpression must refer to a primitive, enumeration or reference type." The query written bellow:
from listing in ctx.listingSource
join listingFile in ctx.ListingFiles
.Where(x => companyIds.Contains(x.CompanyID.Value))
.GroupBy(x => x.ListingID)
.Select(x => new { ListingId = x.Key, Count = x.Count() }) on listing.ListingID equals listingFile.ListingId into listingFilesJoined
from listingFileJoined in listingFilesJoined.DefaultIfEmpty()
select new ListingDTO
{
fileCount = listingFileJoined == null ? 0 : listingFileJoined.Count,
}
How can I resolve this issue without creating class instead anonymous type ?
Upvotes: 0
Views: 229
Reputation: 232
There are no way to select data without creating concrete type =\ There is fix bellow:
.Select(x => new ConcreteType { ListingId = x.Key, Count = x.Count() })
Maybe this answer help someone.
Upvotes: 0