EF5 get hierarchy data self-reference by predicate does not work right.
See original GitHub issueI want to retrieve self-reference data by this method :
public IEnumerable<TEntity> GetAllHierarchy(string navigationPropertyPath, Expression<Func<TEntity, bool>> predicate) { return _entities.Include(navigationPropertyPath).Where(predicate); }
When I use GetAllHierarchy("Children", x => x.ParenetId == null)
data retrived by 2 level Children.
When I call the method without predicate data successfully loaded but I don’t need data with ParentId
This method worked in the EF6 well but in EF5 not working right.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
c# - Setting up hierarchical, self-referencing model in Entity ...
I am trying to create a self-referencing org table in Entity Framework v6 code-first - and I can't seem to get it right....
Read more >Inheritance - EF Core
EF can map a . NET type hierarchy to a database. This allows you to write your . NET entities in code as...
Read more >Using hierarchical data in SQL Server and PostgreSQL with ...
EF Core can then be used to write LINQ queries against the hierarchy to find ancestors and descendants in various ways, as well...
Read more >sitemap6.xml
... /styles-and-templates/templates-structure 2023-01-18T11:05:30+00:00 daily ... https://www.telerik.com/forums/simple-databound-treeview-doesnt-work-why ...
Read more >Latest online resources for UI for WinForms
Hello guys, This thread will be used to post the latest online resources available: RadDock Using Singleton forms in MDI scenario with ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@FakeOwner -
Include
API only loads exactly one level of navigation property. For tracking queries, EF Core performs identity resolution and fix-up navigations between loaded data. Because of this you are seeing above results. EF Core is not loading hierarchy. If you want to load Children collection n-level deep, you have to useInclude/ThenInclude
n times.Also afaik, the query worked same way in EF6 also. If you believe otherwise then as @ajcvickers said above, provide a complete runnable repro which shows what you are seeing.
Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.