Nested Includes, how to query?
See original GitHub issueThis was apparently done in 3.x, yet I haven’t found an example of it in the Wiki or any of the issues.
public class Book
{
[BsonId] public string Id { get; set; }
public List<Author> Authors { get; set; }
}
public class Author
{
public string Role { get; set; }
[BsonRef("users")] public User User { get; set; }
}
public class User
{
[BsonId] public string Id { get; set; }
public string Name { get; set; }
}
I want to query books and get the full User object. How is this possible? I’ve tried:
books.Include(x => x.Authors[0].User).FindById(id);
books.Include("Authors.User").FindById(id);
Both return only the user’s Id
(i.e. no inclusion). Any hints or suggestions would be appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Rails - Nested includes on Active Records?
I'm trying to include every user associated to this event and every profile associated to each user. The Users get included but not...
Read more >How to create a nested include in Sequelize query
Once the associations are created, you can query the data from the three tables by adding a nested include option into your query...
Read more >Rails includes for nested active-record associations
If you want to include an association (we'll call it C) of an already included association (we'll call it B), you'd use the...
Read more >Nested includes and joins - Space Vatican
There are 3 rules for nested :includes: - Always use the association name. Not the table name, not the class name but the...
Read more >Relation queries (Concepts) - Prisma
A key feature of Prisma Client is the ability to query relations between two or more models. Relation queries include: Nested reads (sometimes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @freezy, there is no nested includes for List. In this case it´s better use
Include(Action<T>)
, so you can define your function, likes:books.Include(x => x.Authors.ForEach(z => z.User = users.FindById(z.User.UserId))
Hy, I try to achieve the same thing, but I didn’t get it to work. I already tried the example above with the suggested function (but I guess it should be z.User.Id instead of z.User.UserId): books.Include(x => x.Authors.ForEach(z => z.User = users.FindById(z.User.UserId))
But I get the error message (Cannot convert lambda expression to ‘string’ because it’s not a delegate type)
Is this sample still valid with the version 4.1.4.0?