Neardreams
Neardreams

Reputation: 125

ASP.NET MVC5 EF6 Relation with ApplicationUser

[ForeignKey("Creator")]
public string CreatorID {get;set;}
public virtual ApplicationUser Creator {get;set;}

I have a model which I want to save the creator and modifier. But there are errors during migration

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

TSRDTEST.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.

IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.

IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.

I'm using built in login/logout/register template,with database column prefixs "AspNet", is there any way to fix that error without modify entire project project and preserve the columns with prefix AspNet, Thanks

Upvotes: 4

Views: 420

Answers (1)

Prasanna
Prasanna

Reputation: 189

Actually I didnt understand what you want to do. But the mapping between entities should be look like this.

    public string CreatorID {get;set;}
    [ForeignKey("CreatorID ")]
    public virtual ApplicationUser Creator {get;set;}

Upvotes: 1

Related Questions