Skip to content

must be reducible node on one descendant class #14758

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
natelaff opened this issue Feb 20, 2019 · 5 comments
Closed

must be reducible node on one descendant class #14758

natelaff opened this issue Feb 20, 2019 · 5 comments

Comments

@natelaff
Copy link

natelaff commented Feb 20, 2019

https://github.com/natelaff/reduciblenode

I tried to reproduce this as best I could, but failed to do so.

I have a base type (Post), and two descendant classes, (SubpostA, SubpostB), each with a reference property "Category"

When trying to select a count of assigned category for posts, I get the must be reducible node error.

In this example, you can see it when clicking the two links on the index page.

The weird thing however is in my application, it works for SubpostA class, but the error only throws on SubpostB. In the attached example, it happens on both.

This is newer behavior, as it used to work in 2.x somewhere.

@natelaff
Copy link
Author

natelaff commented Feb 20, 2019

private IQueryable<T> GetBasePostSearchQuery<T>(string searchString, string sortOrder) where T : Post

        {

            var posts = _context.Posts.OfType<T>();                         

            return posts;

        }



        public async Task<IList<PostSearchCategory>> GetPostSearchCategoriesAsync<T>(string searchString) where T : Post

        {

            var query = GetBasePostSearchQuery<T>(searchString, null);

            var result = await query.GroupBy(p => new { ((ICategorizedPost)p).Category, ((ICategorizedPost)p).Category.Slug })

                         .AsNoTracking()

                         .Select(p => new PostSearchCategory { Name = p.Key.Category.Name, Slug = p.Key.Slug, Count = p.Count() })

                         .Where(p => p.Count > 0)

                         .OrderBy(p => p.Name)

                         .ToListAsync();



            return result;

        }

This is where it happens.

@smitpatel
Copy link
Contributor

Casting to interface type may not work properly in EF Core because we lose model information once you do that.

@natelaff
Copy link
Author

That's actually a newer thing I did as I tried to fix this in my actual project. I originally had two (nearly) identical methods that didn't use generics but the actual type and I ended up with the same result.

@ajcvickers ajcvickers added this to the 3.0.0 milestone Feb 22, 2019
@ajcvickers ajcvickers assigned divega and smitpatel and unassigned divega Feb 22, 2019
@natelaff
Copy link
Author

Is there a reason why this would work in one class and not another? I assume it's the way they share a property name but I map to different column names? Anything I can do to workaround in the interim?

@smitpatel
Copy link
Contributor

  • Original repro code is gone.
  • The query was reported on 2.x version. It worked in some previous version due to client eval.
  • One of GroupBy key contains entity type. Closing this as duplicate of Support for GroupBy entityType #17653

@smitpatel smitpatel removed this from the Backlog milestone Dec 9, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants