Getting a weird error after I tried to expand the MVC membership provider in my first MVC3 project.
Errors:
EntityType 'MembershipUser' has no key defined. Define the key for this EntityType.
EntitySet "MembershipUsers" is based on type "MembershipUser" that has no keys defined
I set asp.net standard membership, but added an extra table and model called UserDetails, where the foreign key is the UserId field in aspnet_Users.
Once the record has been inserted into the users table, I get the UserId and try to enter other data in the Useretails table, but this happens when these errors occur. Here is another relevant code. AccountController:
if (createStatus == MembershipCreateStatus.Success)
{
UserRepository _user = new UserRepository();
UserDetails userDetails = new UserDetails();
userDetails.EmployeeNumber = Request.Form["EmployeeNumber"];
userDetails.Title = Request.Form["Title"];
userDetails.FirstName = Request.Form["FirstName"];
userDetails.Initials = Request.Form["Initials"];
userDetails.Surname = Request.Form["Surname"];
userDetails.Nino = Request.Form["Nino"];
_user.AddUserDetails(userDetails, model.Email);
return RedirectToAction("Welcome", "Home");
}
UserRepository:
public MembershipUser GetUserByEmail(string email)
{
MembershipUser user = Membership.GetUser(email);
return user;
}
public void AddUserDetails(UserDetails userDetails, string email)
{
MembershipUser user = GetUserByEmail(email);
Guid userGuid = (Guid)Membership.GetUser(email).ProviderUserKey;
userDetails.UserID = userGuid;
using (IntranetApplication db = new IntranetApplication())
{
db.UserDetails.Add(userDetails);
db.SaveChanges();
}
}
The error starts the db.SaveChanges line.
MemberShip , , -, UserID ? , , , .
-