Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6003583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:32+00:00 2026-05-23T01:08:32+00:00

Getting a weird error after I’ve tried to extend the MVC Membership provider in

  • 0

Getting a weird error after I’ve tried to extend the MVC Membership provider in my code-first MVC3 project.

The errors are:

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 have set up the standard asp.net membership, but added an extra table & model called UserDetails, where the foreign key is the UserId field in aspnet_Users.

Once the entry has been inserted in to the users table, I get the UserId and try to enter the other details in the Useretails table, but that is when these errors appear. Here is the other relevant code. The AccountController:

if (createStatus == MembershipCreateStatus.Success)
            {                    
                //Add other user details
                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; //Add UserID foreign key
        using (IntranetApplication db = new IntranetApplication())
        {
            db.UserDetails.Add(userDetails);
            db.SaveChanges();
        }
    }

The error fires on the db.SaveChanges line.

As MemberShip user is a class itself and not part of entity framework, does anyone know how I can set UserID as a primary key? I’ve checked in the database and it is already set, so don’t know how i can amend it in the code.

Thanks – any help appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:08:32+00:00Added an answer on May 23, 2026 at 1:08 am

    To expand on what Craig is saying, I know it’s convenient to link against the membership tables, but it’s not necessary. Write your queries to accept the user id field as a parameter, then pass it from the Membership.GetUser().ProviderUserKey.

    Also, don’t be tempted to key your tables on UserName, as that can create a security problem if one user creates a user with a specific name, then is deleted, then a new user with the same name is created.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a school project and I'm getting some weird errors from Xcode.
im getting a weird error using this code (part of a class): from sys
I'm getting a really weird error where after I leave the for scope I
I'm getting a weird error when doing this: (.net 2.0) public overrides List<String> getSpaceballs
I'm developing a Silverlight 3 app and getting this really weird error when I
Im getting these weird errors, but I dont understand them. Here are the errors:
I'm getting a weird error and I can't track it down. The stack trace
Trying to install memcached-northscale and getting a weird error. Any help would be appreciated.
For some reason in the testEmployee method I am getting weird error messages saying
I have the following code, from which I am getting an EXC_BAD_ACCESS error: -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.