First MembershipUser and Entity Framework Code

I play with EF Code First and now have difficulties implementing custom MembershipProvider.

For EF Code First, I created my own custom class as follows:

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 MemberhipProvider for EF, but some of them now require MembershipUsereither 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 lost control of Properties. Will this work even with the first EF code?

An alternative idea is to create a ToMembershipUser () method for my user class. Will this be an option? What should I consider?

What is the best way to handle this?

+5
1

, .

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; }
}

, , .

+8

All Articles