I am using the MVC4, as well as the EntityFramework and the SimpleMembershipProvider. I have two DBs, one created with the simplemembership and the other is MyProjectContext. I have a model enrollment:
public class Enrollment
{
public virtual int EnrollmentId { get; set; }
public virtual string Name { get; set; }
public virtual List<UserProfile> Users { get; set; }
}
And in the UserProfile:
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public List<Enrollment> Enrollments { get; set; }
}
And to create the many-to-many relationship:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Enrollment>()
.HasMany(u => u.Users)
.WithMany(r => r.Enrollments)
.Map(m =>
{
m.ToTable("User_Enrollment");
m.MapLeftKey("EnrollmentId");
m.MapRightKey("UserId");
});
}
but when i run it, it creates a table UserProfile in my DB without any users. I want to create a relationship with the table that contains the users and my model. How can i do it? Thanks