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.


Related Articles