c# - EF Linq include nested arrays -


i have 3 classes in ef-code-first

public class user {     public string id { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public virtual icollection<flat> flats { get; set; } }  public class flat {     public string id { get; set; }     public string number { get; set; }     public virtual house house { get; set; }     public virtual icollection<user> users { get; set; } }  public class house {     public string id { get; set; }     public string street { get; set; }     public string number { get; set; }     public virtual icollection<flat> flats { get; set; } } 

and want users.

i do:

var result = _storage.users     .include(x => x.flats)     .include(y => y.flats.select(z => z.house))     .tolist(); 

and in result have users flats, flats don't have houses.

what doing wrong?

you need add 1 include, 1 deepest level:

var result = _storage.users .include(user => user.flats.select(flat => flat.houses)) .tolist(); 

this automatically include houses properties flat properties , houses properties

other flat collections not included. need include.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -