score:2
you need to recursively load permissiondefinitions
that placed in the permissiongroupdefinitionentity
.
first, you should load all permissiongroupdefinitionentities
including its children using the following query :
var query = _dbcontext.permissiongroupdefinitionentity
.asnotracking()
.include(p => p.permissiondefinitions )
.theninclude(p => p.children)
.tolistasync();
since every permissiongroupdefinitionentity
has a list of permissiondefinition
you need a nested loops like this code :
foreach (var permissiongroupdefinitionentity in permissiongroupdefinitionentities)
{
foreach (var permissiondefinitions in permissiondefinitions)
{
}
}
then in the inner loop you should call your recursive function.
see following link (sample for get all children recursively in entity framework core)
this way has terrible performance and i don't recommend that.
in this case it's seems you must write a stored procedure in sql for better performance.
score:0
you can use .theninclude(i => ...)
like so
var query = _context.permissiongroupdefinitionentity
.asnotracking()
.include(i => i.permissiondefinitions)
.theninclude(i => i.group)
.asqueryable();
edit:
var query = _context.permissiongroupdefinitionentity
.asnotracking()
.include(i => i.permissiondefinitions)
.theninclude(i => i.children)
.asqueryable();
Source: stackoverflow.com
Related Query
- Nested include Entity Framework Core
- Entity Framework Core : LINQ advise needed on better approach using include for relational tables
- Why is Entity Framework core loading entity's relations without adding include
- Entity Framework code first - Many to Many - Include conditional
- Entity Framework Core nested expressions
- load related enties without using include in Entity Framework Core
- Entity Framework 6: Include nested nullable many to many children
- How to tell Entity Framework to not include a nested object?
- How to avoid a NullReferenceException when using a nested property via projection with Entity Framework Core
- Include Entity Framework Core (Loop of data)
- Include dynamic Entity Framework Core
- Include Filters for Entity Framework Core
- Entity Framework Core Generic Get with Include and Filter/Search
- Entity Framework Core 3.1 anonymous projections cannot now be used in Linq include statements?
- How do I include the dependent entities of an inherited entity with entity framework core that uses Discriminator column?
- Entity Framework Core "Object reference not set to an instance of an object" with nested .Any in LINQ
- Entity Framework core - Contains is case sensitive or case insensitive?
- Entity framework Include command - Left or inner join?
- Prevent Entity Framework adding ORDER BY when using Include
- Nested query in entity framework
- Join and Include in Entity Framework
- Entity Framework Core count does not have optimal performance
- How to filter nested collection Entity Framework objects?
- Entity Framework recursively include collection for each entity from included collection
- Why does the Entity Framework generate nested SQL queries?
- Entity Framework 6 Code First Custom Functions
- Entity Framework Include OrderBy random generates duplicate data
- Filtering include items in LINQ and Entity Framework
- Use a Inline Table-Valued Functions with Linq and Entity Framework Core
- Entity Framework - Include Take Top N for each parent
More Query from same tag
- how to select the latest date from a IQueryable.GroupBy?
- linq to sql join on multiple columns using lambda error
- Linq Contains without considering accents
- Should I convert this method's queries to Stored Procedures?
- LINQ Datatable return 0 instead of null coalescing
- Grouping each 500 elements of array according to array elements
- EntityFramework Sorting a subset
- Remove item from xml list with Linq
- How to find out the repeated column values from a single datatable based on condition using LINQ
- Determining if an XDocument File Exists
- Combine several similar SELECT-expressions into a single expression
- how to get data from datatable by ( select and Group By)
- Get items which contain any of the strings in a Collection
- How to implement lazy shuffling of Lists in C#?
- Comparing two csv files by column and value and displaying line numbers of differing values
- Linq: Orderby when including multiple tables
- How to open Open XML with Linq
- Best practice for returning IEnumerables from LINQ Methods
- Retain default order for Linq Contains
- C# LINQ/Object Initializers Example from C# 4.0 in a Nutshell
- Select count query or computed column
- how can i get the right fields into a group and sum using linq?
- How to apply search filtration based on AND condition using LINQ MVC
- How do you filter a list based on matching items in another list?
- How to convert xelement to a string in c#?
- Child objects in MongoDB
- NullReferenceException in linq left join, how do I handle the null value?
- LINQ: How to get items from an inner list into one list?
- How to match two Lists with only items that are different in Linq
- How to detemine if sequence has items and if so return the value in LINQ