Using Entity Framework Model First with Asp.Net Me

2019-09-09 05:38发布

问题:

I am currently using MVC4 and entity framework model first. I was wondering how I am supposed to associate the asp.net membership provider tables with entity framework models.

I tried adding membership provider tables into my EF database. But when I make association between UserProfile table from asp.net membership provider and one of my table, another UserProfile table is automatically created and nothing is stored in the original UserProfile table.

Am I supposed to not make any associations between these two and just join table together to get user related information? Is there a work around? Or am I doing it totally wrong?

Thank you!

回答1:

I tried adding membership provider tables into my EF database.

You do not need to add/create Membership tables if you use ASP.NET Universal Providers. It uses Entity Framework Code First, and it'll create required tables automatically if tables are not found.

In new Universal Provider, you won't see tables with prefix aspnet_ anymore.

Relationship

You can use the UserId of User table as primary key in other tables in which you store user related information.

In the following example, XXX_Profile is a custom table. Its primary key is UserId from membership provider's Users table.