EF Core 5:必须是可简化节点
EF Core 5 : must be reducible node
从ef core 3.1迁移到ef core 5后,在执行下面的代码时遇到了这个错误
当 return IntersectList
System.ArgumentException: 'must be reducible node'
private IQueryable<CategoryBrandDto> ToCategoryBrandDto()
{
IQueryable<CategoryBrandDto> Temp = null;
var categoriesBrands = _context.CategoriesBrands;
if (categoriesBrands != null)
{
Temp = categoriesBrands.Select(c => new CategoryBrandDto
{
CategoryId = c.CategoryId,
BrandId = c.BrandId,
Caption = c.Brand.Caption,
OriginalCaption = c.Brand.OriginalCaption,
ImageUrl = c.Brand.ImageUrl,
Arrange = c.Arrange
});
}
return Temp;
}
public IQueryable<BrandDto> GetIntersectsBrand(IEnumerable<BrandDto> filteredBrand, int categoryId)
{
var query = ToCategoryBrandDto().Where(x => x.CategoryId == categoryId).OrderBy(x=>x.Arrange);
var selectedList = new List<BrandDto>();
foreach (var item in query)
{
var cb = new BrandDto()
{
BrandDto_BrandId = item.BrandId,
BrandDto_Caption = item.Caption,
BrandDto_OriginalCaption = item.OriginalCaption,
BrandDto_ImageUrl = item.ImageUrl,
BrandDto_Arrange = item.Arrange
};
selectedList.Add(cb);
}
IQueryable<BrandDto> IntersectList = selectedList.AsQueryable().Intersect(filteredBrand, new ComparerBrand());
return IntersectList;
}
我应该修复什么?
我找到了
代替这一行:
IQueryable<BrandDto> IntersectList = selectedList.AsQueryable().Intersect(filteredBrand, new ComparerBrand());
我是这样修改的:
IQueryable<BrandDto> IntersectList = selectedList.Intersect(filteredBrand, new ComparerBrand()).AsQueryable();
从ef core 3.1迁移到ef core 5后,在执行下面的代码时遇到了这个错误 当 return IntersectList
System.ArgumentException: 'must be reducible node'
private IQueryable<CategoryBrandDto> ToCategoryBrandDto()
{
IQueryable<CategoryBrandDto> Temp = null;
var categoriesBrands = _context.CategoriesBrands;
if (categoriesBrands != null)
{
Temp = categoriesBrands.Select(c => new CategoryBrandDto
{
CategoryId = c.CategoryId,
BrandId = c.BrandId,
Caption = c.Brand.Caption,
OriginalCaption = c.Brand.OriginalCaption,
ImageUrl = c.Brand.ImageUrl,
Arrange = c.Arrange
});
}
return Temp;
}
public IQueryable<BrandDto> GetIntersectsBrand(IEnumerable<BrandDto> filteredBrand, int categoryId)
{
var query = ToCategoryBrandDto().Where(x => x.CategoryId == categoryId).OrderBy(x=>x.Arrange);
var selectedList = new List<BrandDto>();
foreach (var item in query)
{
var cb = new BrandDto()
{
BrandDto_BrandId = item.BrandId,
BrandDto_Caption = item.Caption,
BrandDto_OriginalCaption = item.OriginalCaption,
BrandDto_ImageUrl = item.ImageUrl,
BrandDto_Arrange = item.Arrange
};
selectedList.Add(cb);
}
IQueryable<BrandDto> IntersectList = selectedList.AsQueryable().Intersect(filteredBrand, new ComparerBrand());
return IntersectList;
}
我应该修复什么?
我找到了
代替这一行:
IQueryable<BrandDto> IntersectList = selectedList.AsQueryable().Intersect(filteredBrand, new ComparerBrand());
我是这样修改的:
IQueryable<BrandDto> IntersectList = selectedList.Intersect(filteredBrand, new ComparerBrand()).AsQueryable();