score:1
Try it like this. You might need to change some of the "Select" and "SelectMany" options and the Id field names as you did not post the context.`
var query = _context.Equipment.Include(x => x.Group)
.Include(x => x.Status)
.Include(x => x.Area)
.Include(x => x.EquipmentType)
.Include(x => x.Notes)
.Include(x => x.Department)
.Include(x => x.PMaintenance)
.Include(x => x.MaintenanceHours)
.Include(x => x.Attachments)
.Include(x => x.Request).FirstOrDefault(x => x.EquipmentId == id);
query.Include(x => x.Parts).ThenInclude(x => x.ChildrenParts).SelectMany(x => x.Parts).Where(a => query.Select(q => q.PartsId).Contains(a.Id)).Load();
query.SelectMany(x => x.Parts).SelectMany(x => x.ChildrenParts).Load();
query.SelectMany(x => x.Parts).SelectMany(x => x.ParentParts).Load();
query.SelectMany(x => x.Parts).Select(x => x.Vendor).Load();
query.Include(x => x.SystemInfo).ThenInclude(x => x.SystemUsers).SelectMany(x => x.SystemInfo).Where(a => query.Select(q => q.SystemInfoId).Contains(a.Id)).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.Frameworks).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.VideoCards).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.StorageDrives).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.Software).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.NetworkAdapters).Load();
query.SelectMany(x => x.SystemInfo).SelectMany(x => x.Printers).Load();
query.ToList();
Hope this helps.
Source: stackoverflow.com
Related Articles
- EF Core 3.0 .Include() chain taking ~5-10x longer than 2.2
- Include / ThenInclude with where in EF Core
- .NET CORE 2 EF Include
- Net core EF 3.1 LINQ string comparison no longer working
- EF Core Include On Collection Class Property
- Entity Framework Core : LINQ advise needed on better approach using include for relational tables
- LINQ Source Code Available
- Stored procedure called from C# executes 6 times longer than from SQL Management studio
- .NET 4 Code Contracts: "requires unproven: source != null"
- Why is Entity Framework core loading entity's relations without adding include
- EF Core Include method not working
- creating Linq to sqlite dbml from DbLinq source code
- EF Core Queryable<T>. Count() returns different number than Queryable<T> .ToList().Count(). Is this even possible or is it a bug?
- EF Core "InvalidOperationException: Include has been used on non entity queryable" for navigation property even after explicit include
- EF Core “InvalidOperationException: Include has been used on non entity queryable” on IQueryable
- Include vs. ThenInclude for grandchild properties in EF Core
- Why can I not do more than one level of include in my LINQ statement?
- ef core 5.0 How to Filtered Include
- Nested include Entity Framework Core
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Entity Framework code first - Many to Many - Include conditional
- LINQ include "&&" operator if value is greater than zero
- Extension of IEnumerable's Select to include the source in the selector
- source code for LINQ 101 samples
- EF Core conditional include
- EF Core 3.x - simple LINQ with Include can not be translated, client evaluation
- Exclude deleted child when using EF core Include
- Filtering on Include reverted if I perform Select afterwards in EF Core
- EF Core does not include all the child items
- Include null cells in Linq query from DB in C# code
- Query a Dictionary of Dictionaries?
- Repository Pattern with Caching and SqlMethods
- C#, Best way to loop through NHibernate objects without loading entire set into memory
- MVC, Passing count of 3 tables to view
- IEnumerable Concat Missing, does not contain a definition for 'Concat'
- LINQ error- cannot covert IEnumerable<IEnumerable<object>> to IEnumerable<object>
- LINQ to Entities query in "dot notation"
- Convert Dictionary to a list of Tuples
- Querying a nested list using linq
- Distinct in Linq based on only one field of the table
- How to update all instances of an element in XDocument?
- Remove duplicate in linq list?
- linq join on null
- Select all rows with distinct column value using LINQ
- Filtering a linq using another list of values
- Get distinct items from a list
- Linq .Select() / .SelectMany() automatically uses second, optional parameter
- Linq expression for where condition on entity child
- EF6 Optional 1:1 include not working
- language feature vs framework feature