我试图在2个不同的表上做一个联合,但我开始得到这个错误,因为更新到EF Core 8.完整的错误信息是:
InvalidOperationException:无法翻译设置操作 客户预测已经apply.考虑移动set操作 在最后一次" Select "呼叫之前
下面是我的代码:
var query = dbContext.Servicing
.Include(s => s.Customer)
.Include(s => s.Pictures)
.Where(s => s.CustomerId == customerId)
.Where(i => i.Pictures.Count > 0)
.Select(s => new SiteVisit
{
Id = s.Id,
CustomerId = s.CustomerId,
CustomerName = s.Customer.Name,
Date = s.ServiceDate,
Category = SiteVisitCategory.Service,
ServicingPictures = s.Pictures,
InstallPictures = new List<Picture>(),
})
.Union(dbContext.Installs
.Include(i => i.Order)
.Include(i => i.Pictures)
.Where(i => i.Order.CustomerId == customerId)
.Where(i => i.Pictures.Count > 0)
.Select(i => new SiteVisit
{
Id = i.Id,
CustomerId = i.Order.CustomerId,
CustomerName = i.Order.CustomerName,
Date = i.InstallDate,
Category = SiteVisitCategory.Install,
InstallPictures = i.Pictures,
ServicingPictures = new List<Picture>()
}))
.OrderByDescending(v => v.Date)
.AsNoTracking();
var queryResults = await query.ToListAsync();
我试过移动"Where"子句,但总是出错. 有人能建议我可以try 的其他东西吗?
感谢大家的投入.抱歉没有澄清SiteVisit类是POCO.看起来EF Core无法处理不仅仅是简单的财产分配的预测.我只能假设早期版本的EF完全是在记忆中完成的.最后,我使用CONCAT(无论如何,数据将是唯一的)与单独的查询(根据一些贡献者的建议)检索图片.它读起来不像原文那么优雅,但它很有效.再次感谢