Yustme
Yustme

Reputation: 6255

Custom simple membership provider adding row

I have a custom SimpleMembershipProvider and i have defined all tables that the SimpleMembershipProvider requires, like webpages_Membership:

[Table("webpages_Membership")]
public class Membership
{
    public Membership()
    {
        Roles = new List<Role>();
        OAuthMemberships = new List<OAuthMembership>();
    }

    [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int UserId { get; set; }
    public DateTime? CreateDate { get; set; }
    [StringLength(128)]
    public string ConfirmationToken { get; set; }
    public bool? IsConfirmed { get; set; }
    public DateTime? LastPasswordFailureDate { get; set; }
    public int PasswordFailuresSinceLastSuccess { get; set; }
    [Required, StringLength(128)]
    public string Password { get; set; }
    public DateTime? PasswordChangedDate { get; set; }
    [Required, StringLength(128)]
    public string PasswordSalt { get; set; }
    [StringLength(128)]
    public string PasswordVerificationToken { get; set; }
    public DateTime? PasswordVerificationTokenExpirationDate { get; set; }

    public ICollection<Role> Roles { get; set; }

    [ForeignKey("UserId")]
    public ICollection<OAuthMembership> OAuthMemberships { get; set; }
}

But how do i add a record in this table within the Seed() method in the configuration.cs file that migrations creates when enabled?

Upvotes: 0

Views: 345

Answers (1)

Kevin Junghans
Kevin Junghans

Reputation: 17540

Assuming you have the custom membership provider correctly configured in the web.config you should be able to add a record in the Seed method by doing this.

 var membership = (MyMembershipNamespace.SimpleMembershipProvider)Membership.Provider;
 membership.CreateUserAndAccount("test", "password");

Upvotes: 1

Related Questions