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
its because you are not doing
.Include(x => x.Reactions)
in your query
relationships are not eagerly loaded unless specifiedoh I forgot
but wait
I dont want to qury post , i just want to query the reaction
?
post.Reactions.(x => x.Reactions).Count(r => r.IsLike)
no
You are fetching post from
_postRepository.GetPost
and THAT is where your EF query is taking place
thats where you need to include reactionsthank you
ApplicationUser? user = await _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));
how i can include the reaction hereyou 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 somethingis there any point of adding navigation to the application user class ?