0 votes
in Education by (1.7m points)
I have a Member class:

public class Member


    // key

    public Guid UserId { get; set; }

    // some other fields


Also I have a aspnet_Users table with has UserId primary column.

We can:

1). Add additional property MembershipUser to the Member object and get it's value by calling Membership.GetUser(this.UserId) method.

Also I've add

context.Database.ExecuteSqlCommand("ALTER TABLE [dbo].[Members]  WITH CHECK ADD  CONSTRAINT [FK_Members_aspnet_Users] FOREIGN KEY([UserId]) REFERENCES [dbo].[aspnet_Users] ([UserId])");

to the DataContext.Seed() method to ensure that Member can not be added without aspnet_Users account.

2). Use fluent API in OnModelCreating. If this a good case how to map them correctly?

What's the best choice? Any thoughts?

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
No matter how I tried to avoid it, I've found the best approach is to implement my own MembershipProvider and have it use my model, rather than trying to shoehorn my model into the built-in membership provider.

If you are going down the other route you have to map the ASP.NET Membership tables to your domain and derive your Member class from the ASP_User class (or vice versa if you want to ensure that all Users you create are Members). In the end, I've discovered that although it seems like more effort up front, implementing MembershipProvider is the easier approach.