0

I'm in the process of getting my head around how the new SimpleMembership provider works in MVC 4 with EF Code First. So far I've got everything working pretty well, but I'm running into something I just don't quite understand.

SimpleMembership auto-creates several tables as a result of this line of code:

WebSecurity.InitializeDatabaseConnection("DatabaseContext", "User", "Id", "Email", autoCreateTables: true);

I have a Code First entity called "User" to store all of my domain specific user data. So using the WebSecurity class, I can get the user id I need in various ways and then query my User entity to get to my domain specific data. However, since there are no POCO classes for the "webpages_xxxx" tables that SimpleMembership auto-creates, I can't easily access those via EF. Specifically I'm interested in getting at the webpages_Membership table so that when I have a user ID, I can get at fields like "IsConfirmed", "PasswordVerificationToken", etc.

Common sense says I'd just need to code some POCO classes to represent the table structures, but it feels like there should be something a little more out-of-the-box. Did Microsoft leave us to just code our own POCO classes to represent their table structure or am I missing something?

Scott
  • 13,735
  • 20
  • 94
  • 152

1 Answers1

0

If i understood , Your scenario is: Use SimpleMembership, yet access the data using code first where my tables reside in the same DB.

This is possible. I use a nice tool from EF team, http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d for such purposes.

With the EF powertool, you can generate CodeFirst code for accessing an existing DB.

HOW: Install the powertool. (See link above) Place mouse on the Project were the code should go. Right click on project, select Entity Framework, reverse engineer codefirst from Database.

Bingo. POCO classes you can add to your model and to YOUR context. And your can read and write to the standard the membership tables.

phil soady
  • 11,043
  • 5
  • 50
  • 95