There is such code:
public static List<Model.Stores> SelectStoresForTable(string reg="", string rtl="", string reprInitials="") { IQueryable<Model.Stores> query = db.stores; if (!string.IsNullOrEmpty(reg)) query = query.Where(s => s.region.Name == reg); if (!string.IsNullOrEmpty(rtl)) query = query.Where(s => s.rtl.Name == rtl); if (!string.IsNullOrEmpty(reprInitials)) query = query.Where(s => s.repr.initials == rtl); return query.ToList(); } This code, if there are any parameters other than the default, filters out the data; if not, it returns a list of all stores. Each store has relationships with other objects (region, person, etc.). And only “simple variables” (string and id) are unloaded into the final list, and all dependencies are null (person, region, etc.). I just can not understand what the problem is. The database has these dependencies. Looks like some kind of mistake in the Entity Framework itself. I have a CodeFirst database.
If I turn on the program from the completed database, then there is an error. If I drop the tables from the running program and load the information into them again, then everything works like a clock. Maybe someone came across?
Thank you very much in advance.
Update: I received an answer to the question thanks to @Bald Another very important point, I was not connected:
using System.Data.Entity; Therefore, I could not enter anonymous functions in .Include ().
Include(x=>x.Навигационное свойство) / Load()or use the lazy load. more details in the link below - BaldInclude()download - Bald