EF Core 5 : must be reducible node

6.3k views Asked by At

after migrating from ef core 3.1 to ef core 5, I encountered this error in executing the following code when 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;
    }

What should I fix?

1

There are 1 answers

0
fery KHan On BEST ANSWER

im found

Instead of this line:

 IQueryable<BrandDto> IntersectList = selectedList.AsQueryable().Intersect(filteredBrand, new ComparerBrand());

I modified it this way :

  IQueryable<BrandDto> IntersectList = selectedList.Intersect(filteredBrand, new ComparerBrand()).AsQueryable();