How to correctly implement other entity's reference to Identity user?

前端 未结 2 902
春和景丽
春和景丽 2021-01-21 10:13

I\'m using Identity which has his own context.

public class ApplicationUser : IdentityUser {
    // some custom fields
}

public class IdentityContext : Identity         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 11:02

    Example:

    public class ApplicationUser : IdentityUser {
        // some custom fields
    }
    
    public class Comment{
       public int Id {get;set;}
       public string Message{get;set;}
       public DateTime Time{get;set;}
       public string AuthorId {get;set}
       [ForeignKey("AuthorId")]
       public virtual ApplicationUser Author {get;set;}
    }
    
    public class MyContext :IdentityDbContext {
    
    public MyContext(): base("DefaultConnection", false){ }
    
       public DbSet Comments { get; set; }
       //... other DbSets
    }
    

    I always flow this pattern. Hopefully it's help you.

提交回复
热议问题