C
C#4w ago
its0mar

relationship navigations entity framework

post class and ApplicationUser class both have a collection of Reaction but when i try to get the reaction count its always zero line : https://github.com/Its0mar/ZeroWebRepo/blob/88f8b0f9f7792a0146325d6054fc60a6097f4ee8/Services/PostService.cs#L52
GitHub
ZeroWebRepo/Services/PostService.cs at 88f8b0f9f7792a0146325d6054fc...
Contribute to Its0mar/ZeroWebRepo development by creating an account on GitHub.
8 Replies
Pobiega
Pobiega4w ago
its because you are not doing .Include(x => x.Reactions) in your query relationships are not eagerly loaded unless specified
its0mar
its0marOP4w ago
oh I forgot but wait I dont want to qury post , i just want to query the reaction
Pobiega
Pobiega4w ago
?
its0mar
its0marOP4w ago
post.Reactions.(x => x.Reactions).Count(r => r.IsLike)
Pobiega
Pobiega4w ago
no You are fetching post from _postRepository.GetPost and THAT is where your EF query is taking place thats where you need to include reactions
its0mar
its0marOP4w ago
thank you ApplicationUser? user = await _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier)); how i can include the reaction here
Pobiega
Pobiega4w ago
you can't So fetch the user like that, but loading the reactions will be its own call you could have a ReactionsRepository.GetForUser(Guid userId) or something
its0mar
its0marOP4w ago
is there any point of adding navigation to the application user class ?

Did you find this page helpful?