linq到EF4查询中的DbIsNullExpression异常

时间:2015-07-15 09:13:21

标签: c# .net linq entity-framework-4

我已经写了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,
}

如何在不创建类而不是匿名类型的情况下解决此问题?

1 个答案:

答案 0 :(得分:0)

没有创建具体类型= \无法选择数据 有修复方法:

.Select(x => new ConcreteType { ListingId = x.Key, Count = x.Count() }) 

也许这个答案对某人有帮助。