I'm using VS 2015 and the latest version of ASP.NET Identity 2.2.1 in MVC 5 project.
I have this simple model:
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public ApplicationUser SomeUser { get; set; }
}
Basically, 1-to-1 relationship with ApplicationUser
. And a usual context;
public class Db : DbContext
{
public DbSet<Student> Students { get; set; }
}
I now go and do Enable-Migrations
for this context. Everything works fine. I then go and do Add-Migration SomeInitialMigration
and get the following:
WebApplication18.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
WebApplication18.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.
If I first start the app (and the database tables are created), this error occurs when I type Enable-Migrations
.
I've been reading on how to solve this, implemented this SO answer solution, however, now not only it doesn't solve the problem, but when I hit 'Register' for a new user, or 'Login', I get:
ApplicationUser_Logins_Target: : Multiplicity is not valid in Role 'ApplicationUser_Logins_Target' in relationship 'ApplicationUser_Logins'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be '1'.
I've also tried only adding base.OnModelCreating(modelBuilder);
in ApplicationDbContext
as suggested by this SO snswer but nothing happened as well.
I'm not sure what to do, pretty much tried all SO solutions to similar problems. Maybe something changed with Identity source code and no longer work.
Basically, what I'm trying to accomplish is this: I Want to connect so an ApplicationUser has many students. And I've tried testing this so I add a simple relationship to Student
for a start, nothing fancy. So knowing this, if there's any alternative approach that's worth taking to connect a registered users to custom models via one-to-many or one-to-one, please let me know.