linq to EF4 查询中的 DbIsNullExpression 异常
DbIsNullExpression exception in linq to EF4 query
我已经编写了 linq EF4 查询,但它因异常而失败"DbIsNullExpression must refer to a primitive, enumeration or reference type." 的参数如下所示:
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,
}
如何在不创建 class 而不是匿名类型的情况下解决此问题?
fileCount = (int?)listingFileJoined.Count ?? 0
如果不创建具体类型就无法 select 数据 =\
修复如下:
.Select(x => new ConcreteType { ListingId = x.Key, Count = x.Count() })
也许这个答案对某人有帮助。
我已经编写了 linq EF4 查询,但它因异常而失败"DbIsNullExpression must refer to a primitive, enumeration or reference type." 的参数如下所示:
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,
}
如何在不创建 class 而不是匿名类型的情况下解决此问题?
fileCount = (int?)listingFileJoined.Count ?? 0
如果不创建具体类型就无法 select 数据 =\ 修复如下:
.Select(x => new ConcreteType { ListingId = x.Key, Count = x.Count() })
也许这个答案对某人有帮助。