0
votes

I have a model class defined like so:

public class Request
{
    public int Id { get; set; }
    [ForeignKey("Requester")]
    public string RequesterId { get; set; }
    public virtual ICollection<ApplicationUser> Requester { get; set; }
}

I'm simply making a foreign key relationship between a request and the user that made the request. However, when I try and perform an Add-Migration, I receive the following error:

Project.DataContexts.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. Project.DataContexts.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've looked around and the only similar situations are where people are using Fluent-API, with modelbinding. I'm however using data annotations. Any help on this? Thank you!

1

1 Answers

0
votes

The error tells you exactly what the problem is. Your IdentityUserLogin and IdentityUserRole classes have no property that is marked with [Key] or can be interpreted as the primary key based on convention. Why you didn't both to post the classes that are explicitly mentioned in the exception is beyond me.