Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why Include() is not loading all nested items #2479

Open
Josip84 opened this issue May 15, 2024 · 0 comments
Open

Why Include() is not loading all nested items #2479

Josip84 opened this issue May 15, 2024 · 0 comments
Labels

Comments

@Josip84
Copy link

Josip84 commented May 15, 2024

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant