Starts in:
1 DAY
23 HRS
30 MIN
51 SEC
Starts in:
1 D
23 H
30 M
51 S
Open Closed

Add relation between AbpUser to My Table in 5.0 #2151


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

In other versions of abp exists an entity called AbpUser, in the new version this entity not exists. What is the right way to create a relation of my entity to user abp entity.

I'm usind EF.

Thank you,


9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It is now easier to create the relationship between the entity and the user, you just need to use IdentityUser as the navigation property.

    Example:

    public class MyEntity : ...
    {
      public Guid IdentityUserId {get;set;}
      public IdentityUser IdentityUser {get;set;}
    }
    
  • User Avatar
    0
    jhsanc created

    Everything founds good but I have only this issue using abp suite code generator, made this method:

    But AppUser not exists in current db context, how can I do to replace this context for Identity Context.

    Thank you,

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try:

    (await GetDbContextAsync()).Users
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Also , can you share the steps? it may a problem, we should fix it if so.

  • User Avatar
    0
    jhsanc created

    Hi,

    You can try:

    (await GetDbContextAsync()).Users 
    

    This not found because users not exists in DbContext: See the DbSets:

  • User Avatar
    0
    jhsanc created

    Also , can you share the steps? it may a problem, we should fix it if so.

    Sure, I'm using abp suite to generate the code, then I create new entity called Person and define a navigation property in abp suite: This create a repository with this method, but this method not found because Users not exists en current db context. Users is not defined in DbSets

  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try use ReplaceDbContext.

    See, you should use IIdentityProDbContext:

    https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs

  • User Avatar
    0
    jhsanc created

    Hi,

    It is now easier to create the relationship between the entity and the user, you just need to use IdentityUser as the navigation property.

    Example:

    public class MyEntity : ... 
    { 
      public Guid IdentityUserId {get;set;} 
      public IdentityUser IdentityUser {get;set;} 
    } 
    

    Hello this relationship definition create the next warning:

    The foreign key property 'Person.IdentityUserId1' was created in shadow state because a conflicting property with the simple name 'IdentityUserId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can configure foreign keys manually: https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api,fluent-api-simple-key,simple-key#foreign-key

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