Search code examples
c#asp.net-coreentity-framework-coreaspnetboilerplate

I define a Property on User Class,But I can't Get It's Value on Login Action


Define Property

enter image description here

Try Get Value

enter image description here

I don't know what I should be doing,I have to use department Repository get the value?


Solution

  • For your issue, it is caused by that GetLoginResultAsync which calls LoginAsync did not load your Department navigation property.

    For a workaround, you could requery User by IRepository<User, long> _userRepository with loginResult.User.Id like below:

    _userRepository.GetAllIncluding(u => u.Claims,
                                    u => u.CreatorUser,
                                    u => u.DeleterUser,
                                    u => u.Roles,
                                    u => u.Department).FirstOrDefault(u => u.Id ==loginResult.User.Id);