would really appreciate a bit of guidance on how to use ApplicationUser within my own custom class in MVC5.
Simple model, using scaffolding to create controller and view, sm DbContext for the default ApplicationUser (IdentityUser) from the Internet Application template. I want to use the ApplicationUser to stamp the transaction with the details of whoever was logged in at the time.
I get one of two database errors when Entity Framework tries to DropAndRecreateAlways
First my class:
public class Example
{
public int ID { get; set; }
[Required]
public string Description { get; set; }
[Required]
public double Amount { get; set; }
[Required]
public virtual ApplicationUser CreatedBy {get; set;}
[Required]
public virtual ApplicationUser ModifiedBy { get; set; }
}
Errors I get when Entity Framework tries to create the database are:
{"One or more validation errors were detected during model generation:\r\n\r\nMvcApplication1.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.\r\nMvcApplication1.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.\r\nIdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.\r\nIdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.\r\n"}
A referential integrity due to Cascade on Delete (I can override DbContext to remove cascading deletes)
What is the best way to achieve this? Any guidance would be appreciated.