How can I use Entity Framework with Membership tables? entity-framework


I don't know where to start since I have never used Entity Framework in a project before. I am utilizing the membership tables produced by the ASP.Net membership service in their current state.

I want to create an object that has a user reference. For instance

public int Id {get;set;}
public User User{get;set} // Where User is some object relating to Membership provider User.
public string Application {get; set;}

Since I am utilizing EF in a code-first manner, I would want to allow it to create tables based on this object. How can I set this up such that EF understands that I'm making a connection to a user under Membership control? What type should I substitute for "User" in the aforementioned example? (what is the type)

Sorry if it was unclear. I only want an illustration or explanation of how EF connects with the membership provider schema in ASP.NET.


6/22/2011 10:28:00 PM

Accepted Answer

You may use the aspnet regsql.exe program to add the ASP.NET Membership tables to your current database if you wish to have a single EF model linking your membership tables and application tables. Several links

You may create EF Code classes that adhere to the membership schema after the Membership tables have been deployed. I provided a thorough overview of the procedure here:

using an existing database to create EF Code First model classes

6/23/2011 3:28:00 AM

Popular Answer

I'd suggest you could create a "AppUser" entity (your own unique user object) whose corresponding table has a foreign key to the aspnet Membership table's "UserID" field. By doing this, it will be simpler to modify or add attributes to your "AppUser" Entity rather than attempting to alter the MS table structure (which can be a real pain). Using resources like the MvcMembership starting Kit DLLs, you may still interact with the built-in MS Membership classes and methods from your MVC project.

Hope this is useful!

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow