Migrating Auth to Core 2.0: The entity type 'IdentityUserRole<int>' requires a primary key to be defined -


i migrating app asp.net core 2.0.

https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x

in above article, has following mapping:

protected override void onmodelcreating(modelbuilder builder) {     base.onmodelcreating(builder);     // customize asp.net identity model , override defaults if needed.     // example, can rename asp.net identity table names , more.     // add customizations after calling base.onmodelcreating(builder);      builder.entity<applicationuser>()         .hasmany(e => e.claims)         .withone()         .hasforeignkey(e => e.userid)         .isrequired()         .ondelete(deletebehavior.cascade);      builder.entity<applicationuser>()         .hasmany(e => e.logins)         .withone()         .hasforeignkey(e => e.userid)         .isrequired()         .ondelete(deletebehavior.cascade);      builder.entity<applicationuser>()         .hasmany(e => e.roles)         .withone()         .hasforeignkey(e => e.userid)         .isrequired()         .ondelete(deletebehavior.cascade); } 

it looks fine me. however, when run

dotnet ef migrations add initialcreate 

i following error:

the entity type 'identityuserrole' requires primary key defined.

applicationuser defined follows:

public class applicationuser : identityuser {     /// <summary>     /// navigation property roles user belongs to.     /// </summary>     public virtual icollection<identityuserrole<int>> roles { get; } = new list<identityuserrole<int>>();      /// <summary>     /// navigation property claims user possesses.     /// </summary>     public virtual icollection<identityuserclaim<int>> claims { get; } = new list<identityuserclaim<int>>();      /// <summary>     /// navigation property users login accounts.     /// </summary>     public virtual icollection<identityuserlogin<int>> logins { get; } = new list<identityuserlogin<int>>();      public string fullname { get; set; } } 

is there wrong mapping?

try adding

builder.entity<identityuserrole<int>>().haskey(p => new { p.userid, p.roleid}); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -