我已经写了linq EF4查询,但它失败了,异常" DbIsNullExpression的参数必须引用原语,枚举或引用类型。" 下面写的查询:
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,
}
如何在不创建类而不是匿名类型的情况下解决此问题?
答案 0 :(得分:0)
没有创建具体类型= \无法选择数据 有修复方法:
.Select(x => new ConcreteType { ListingId = x.Key, Count = x.Count() })
也许这个答案对某人有帮助。