C
C#2y ago
DarkVader

✅ .Where in Include stetment not returning correctly

queryable
.Include(x => x.Comments
.Where(x => x.NestedLevel == 0 && x.ParentId == null)
.OrderByDescending(x => x.CreatedAtUtc)
.Skip(0)
.Take(5)
).ThenInclude(x => x.Comments
.Where(x => x.NestedLevel == 1)
.OrderByDescending(x => x.CreatedAtUtc)
.Take(3)
);
queryable
.Include(x => x.Comments
.Where(x => x.NestedLevel == 0 && x.ParentId == null)
.OrderByDescending(x => x.CreatedAtUtc)
.Skip(0)
.Take(5)
).ThenInclude(x => x.Comments
.Where(x => x.NestedLevel == 1)
.OrderByDescending(x => x.CreatedAtUtc)
.Take(3)
);
I dont understand why does this pull from database like this, shouldnt it be 5 Comments on first level (with NestedLevel == 0) and then inside of them list with comments with (NestedLevel == 1) like a tree , for some reason this pulls 8 comments in the root level list, where not all comments are NestedLevel = 0, I am so confused, I am reading documentation and it shouldnt behave like this.
5 Replies
Monsieur Wholesome
That is not how include works Include is solely there to navigate to foreign key properties that will be included in the result set of objects The .Where comes after including your foreign key properties
DarkVader
DarkVaderOP2y ago
So I need to use select? That way I am losing tracking for comments properties
Saber
Saber2y ago
you can filter inside includes
Monsieur Wholesome
Oh can you? What would be the difference to separating it?
DarkVader
DarkVaderOP2y ago
You can in versions above 5 I think, and that tracks entities unlike using Select, from what I read, but somehow I can't make it work on nested properties, I've been trying for 6 hours straight to make it work and I just can't so I decided to ask people here for help So i was dumb and i designed data incorrectly, my bad, now I fixed an error, Ill close this
Want results from more Discord servers?
Add your server