Many to Many relationship in Asp.Net MVC 5 with Identity table and Custom table

前端 未结 3 1162
野的像风
野的像风 2021-01-06 16:46

I\'m trying to make a relationship between the Users from the table generated by Asp.Net Identity with my own table. The relationship must be many to many, since many Users

3条回答
  •  离开以前
    2021-01-06 17:29

    You can try it as shown below using Fluent API.

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
    
        modelBuilder.Entity()
                    .HasMany(s => s.Users)
                    .WithMany(c => c.Tasks)
                    .Map(cs =>
                            {
                                cs.MapLeftKey("TaskRefId");
                                cs.MapRightKey("ApplicationUserRefId");
                                cs.ToTable("TaskApplicationUser");
                            });
    
    }
    

    Update : you can see this link too.

    EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType

提交回复
热议问题