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

  • SEARCH
  • Home
  • 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 6375945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:40:52+00:00 2026-05-25T01:40:52+00:00

I am playing around with EF Code First and now ran into trouble when

  • 0

I am playing around with EF Code First and now ran into trouble when implementing a custom MembershipProvider.

For EF Code First I created my own user class like this:

public class User
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }
    [Required]
    public string UserName { get; set; }
    [Required]
    public string Password { get; set; }
    [Required]
    public string Email { get; set; }
    [Required]
    public bool IsApproved { get; set; }
    public DateTime? LastLoginDate { get; set; }
    public DateTime? LastActivityDate { get; set; }
    [Required]
    public DateTime CreationDate { get; set; }
    [Required]
    public string ApplicationName { get; set; }
}

I also implemented some functions of my custom MembershipProvider for EF already, but some of them now require MembershipUser as either a parameter or a return value.

    public MembershipUser GetUser(string username, bool userIsOnline)

My first thought was to inherit my User class from MembershipUser, but then I lose the control over the Properties. Would that even work with EF Code First?

An alternate idea is to create a ToMembershipUser() method for my user class. Would that be an option? What would I have to consider?

What’s the best way to handle this?

  • 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-25T01:40:53+00:00Added an answer on May 25, 2026 at 1:40 am

    You can use the Adapter Pattern to solve this problem.

    public class CustomUser : MembershipUser
    {
        public CustomUser(string providername,
                        User userAccount) :
            base(providername,
                            userAccount.UserName,
                            userAccount.Id,
                            userAccount.Email,
                            passwordQuestion,
                            string.Empty,
                            true,
                            false,
                            userAccount.CreationDate,
                            userAccount.LastLoginDate,
                            userAccount.LastActivityDate,
                            new DateTime(),
                            new DateTime())
        {
            UserAccount = userAccount;
        }
    
        public User UserAccount { get; private set; }
    }
    

    Customize the parameters passed to the base constructor depending on what your entity model has.

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

Sidebar

Related Questions

I'm playing around with EF Code First and need some help. A User can
I'm playing around with GHCi for the first time, and I'm having some trouble
I have been playing around quite a lot with EF4 Code First and I
I been playing around with my code and I wanted to see what would
Here is some C++ code I'm playing around with: #include <iostream> #include <vector> #define
Just playing around with the now released Silverlight 2.0. I'm trying to put a
This is my first post, so please be gentle. I've been playing around with
I have been playing around with Scala parser combinators for some time now, and
I am playing around with validating form inputs. For now I'm simply having fun
I'm just playing around for the first time with jQuery's ajax functionality. I wanted

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.