question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF5 get hierarchy data self-reference by predicate does not work right.

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Apr 19, 2021

@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 use Include/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.

1reaction
ajcvickerscommented, Apr 12, 2021

Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found