I have an entity called Position with foreign key to itself: int Id; and int ParentId;.This gives me two navigation properties: Position Parent; and List<Position> Children;. When I'm loading the entire table into EF context (tracked), I'd like EF to populate those properties without emitting additional SQL joins (since all participating entities are being loaded anyways). Is there any way to achieve this during query creation or later, maybe something like db.Entry(positions[0]).Collection(x => x. Children).Load();, but limited to already tracked entities?
In Entity Framework Core, how to populate self-referencing navigation collection without additional Include (using only entities already tracked)?
27 Views Asked by Ivan Koshelev At
1
There are 1 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in ENTITY-FRAMEWORK-CORE
- Will it slow down the performance when Unit of work pattern is used with EF Core
- Entity Framework Core 8 dbcontext - can't add some rows in many-to-many relationship
- Upsert huge amount of data by EFCore.BulkExtensions
- .NET Core 8, how can I add properties to user account that contains multiple values?
- How to load data from a different context in Entity Framework Core?
- Passing GUID value through SqlQuery will raise the error: invalid input syntax for type uuid
- The specified data type in the EF modelBuilder doesn't correspond to the one that is created
- EntityFrameworkCore.DbUpdateException: Unable to delete row, SQL Syntax error
- Create one entity for multiple tables?
- I'm getting an error, when trying to communicate with db, it seems like something with verses, but I've already changed it and the error continues
- Issue with Entity Framework Core: .Include() and .AsNoTracking() not displaying expected related entities
- Entity Framework Core 8 throws "Method not found: 'Void CoreTypeMappingParameters..ctor" error
- EF Core is creating a table not in the migration
- Can I share a List<T> property across multiple queries via a tracking DbContext?
- Revert database context to previous state EF Core 7
Related Questions in NAVIGATION
- Why might react-router navigate(-1) go back two routes/pages?
- In @react-navigation's Tab.Navigator, I aim to lock the final screen while allowing the rest to scroll
- (ros melodic) Lidar odometry is not working well
- How to jump to a div using keyboard shortcuts?
- Flutter: How to use a BottomSheet in a BottomNavigationBar?
- Force security constraint managed 403 error when hitting restricted page with h:commandLink
- In Entity Framework Core, how to populate self-referencing navigation collection without additional Include (using only entities already tracked)?
- Blogger next previous navigations missing
- Cannot achieve live navigation using js,openstreetmap and leaflet
- Im using mapbox sdk navigation v2 and have a problem with the cycling view
- Assigning sensor information to image coordinates
- Blazor InteractiveServer navigate to external link whilst JWT added to the request headers?
- Navigate to a different page from the side bar drawer without using the bottom navigation bar using persistent flutter package
- WPF C# - Textblock inputs not saving on Navigation to new page?
- React Chrome vs Firefox Navigation is not defined
Related Questions in SELF-JOIN
- How do I represent self-joined data in a RESTful API
- Does PostgreSQL self join ignore indexes?
- sqlite self join with where clause
- In Yii2, how do I join a table to itself?
- Mysql: Create a view with multiple self joins without duplicates in result
- How to self join a many to many table in cakephp 3?
- Select whole team either by using parent_id or child_id : Mysql
- Is it possible to execute a self join in Sequel?
- SQL - Multi level self join
- mysql self join returning blank values
- Hive : Fill in missing columns
- CakePHP 3 CounterCache not updating on delete with belongsToMany SelfJoinTable
- SQL - Compare rows in a table to find column differences - self join
- Get unique values from a MySql table column grouped with other column
- SQL Update Query running forever. Oracle Performace Tuning Tips required
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If you have loaded all related positions as tracked entities then you should find that the relationships are already populated when leaving off the
Include. Eager loading is generally recommended as without it EF will only populate references from the tracking cache which might be only an incomplete representation of the state. If you can safely assume that all related positions are loaded and tracked then you can ignore adding theInclude. I'd probably throw a comment in there explaining that at that point all positions should have been loaded. Any optimizations or re-factoring could break your current expected behavior.