Saturday, 17 August 2013

ASP .NET MVC 4 User.IsInRole overriding Entity Framework usertypes & roles

ASP .NET MVC 4 User.IsInRole overriding Entity Framework usertypes & roles

This must have an answer but i can't find it anywhere so i fully expect
someone will just comment a link to an answer but here goes.
I have my entities setup like this: UserProfile 1:1 > UserType 1:n>
UserRoles.
My Issue is when I come to use User.IsInRole("xxxx") entity framework
returns an error that webpages_usersinroles has not been created.
If I added the following to my context on model binding, then I get an
error with the UserId column not being present. So I believe I need to
possibly extend/override the role providers User.IsInRole... can anyone
point me in the right direction.
modelBuilder.Entity<UserType>()
.HasMany<UserRole>(r => r.Roles)
.WithMany(u => u.UserTypes)
.Map(m =>
{
m.ToTable("webpages_UsersInRoles");
m.MapLeftKey("UserTypeId");
m.MapRightKey("RoleId");
});

No comments:

Post a Comment