I have followed the following and used ApplicationUser
instead of creating my own. ApplicationUser
comes from the default MVC 5 application:
This is my ApplicationUser
code:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync( UserManager<ApplicationUser> manager )
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync( this, DefaultAuthenticationTypes.ApplicationCookie );
// Add custom user claims here
return userIdentity;
}
public virtual ICollection<Field> Fields { get; set; }
}
And this is my Field
code:
public class Field
{
[Key]
public int FieldID { get; set; }
// [ForeignKey( "Id" )] // Not sure if i needed this but neither worked
public virtual ApplicationUser CreatedBy { get; set; }
...
But the following errors occur when i run PM> Add-Migration AddedCreatedByToFields
:
One or more validation errors were detected during model generation:
FieldApplication.Domain.Concrete.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
FieldApplication.Domain.Concrete.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.
Any ideas what i'm doing wrong?
Side note
I moved my ApplicationUser
code into a seperate project called Domains. I included the Identity Nuget package to get the namespaces in it...