Why Include() is not loading all nested items
Josip84 opened this issue · 0 comments
Josip84 commented
Here is my example:
static void Main(string[] args)
{
Occupation occupation = new Occupation()
{
OccupationName = "Oc"
};
Names names = new Names()
{
Name = "a",
LastName = "b",
Occupation = occupation
};
List<Names> nameslist = new List<Names>();
nameslist.Add(names);
MyMainClass myMainClass = new MyMainClass()
{
ID = 1,
Names = nameslist
};
using (var db = new LiteDatabase(@"MyData.db"))
{
var col = db.GetCollection<MyMainClass>(nameof(MyMainClass));
col.EnsureIndex(x => x.ID, true);
col.Insert(myMainClass);
var r = col
.Include(x => x.Names)
.FindAll()
.FirstOrDefault();
Console.WriteLine(r);
}
}
public class MyMainClass
{
public int ID { get; set; }
public List<Names> Names { get; set; }
}
public class Names
{
public string Name { get; set; }
public string LastName { get; set; }
public Occupation Occupation { get; set; }
}
public class Occupation
{
public string OccupationName { get; set; }
}
Running this only loading only Names but Occupation is null.
I also tried on this way
var r = col .Include(x => x.Names) .Include(x => x.Names.Select(n => n.Occupation)) .FindAll() .FirstOrDefault();