Open Closed

ABP Suite: How to Add the User Entity as a Navigation Property of Another Entity #2801


User avatar
0
zhongfang created
  • ABP Framework version: v5.1.4
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

https://community.abp.io/posts/abp-suite-how-to-add-the-user-entity-as-a-navigation-property-of-another-entity-furp75ex

I follow above topic. But I got an error. (await GetDbContextAsync()).Users There is no property named Users in EasyCommentDbContext.

 protected virtual async Task<IQueryable<CommentWithNavigationProperties>> GetQueryForNavigationPropertiesAsync()
        {
            return from comment in (await GetDbSetAsync())
                   join appUser in (await GetDbContextAsync()).Users on comment.AppUserId equals appUser.Id into users
                   from appUser in users.DefaultIfEmpty()

                   select new CommentWithNavigationProperties
                   {
                       Comment = comment,
                       AppUser = appUser
                   };
        }

3 Answer(s)
  • User Avatar
    0
    zhongfang created

    I created 2 files as below

    Yee.EasyComment.Application.Contracts.Users

        public class AppUserDto : IdentityUserDto
        {
        }
            
    

    Yee.EasyComment.Domains.Users

        public class AppUser : IdentityUser
        {
        }
    
  • User Avatar
    0
    zhongfang created

    Waiting for reply……

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    It is not a good practice to inherit from IdentityUser. I would suggest using Object Extensions.

    Or create a different entity isolating your user-related business:

    public class AppUser: Entity<Guid>
    {
        public Guid IdentityUserId {get; set;}
        public IdentityUser User {get; set;
    }        
    

    You can event use the same IdentityUserId for AppUser if you care.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11