简体   繁体   中英

Asp.Net Membership - Providers in Entity Framework 4

I have a website using ASP.NET Membership, Entity Framework 4 in place and MS SQL 2008 for DB.

I would like to know if using ASP.NET Membership the interaction with the database will be pass using Entity Framework?

Thanks for your help!

Upvoted on Musa's answer to remove the negative. There's no mention of custom membership provider, but that doesn't mean it isn't the answer.

He's spot on right, there is no EF4 specific provider shipped with the framework but you can build your own.

This actually consolidates the problem domain, in that you can CLEANLY link users into the rest of your entity objects rather than treating membership as a separate black box that you have to tip-toe around.

The way to do that is indeed by inheriting from MembershipProvider and implementing the abstract methods.

Once you've done that you can do whatever you want with users etc rather than living in fear of breaking the SQLMembership tables and stored procedures that you get by default - which I don't like using as they are ugly.

I've just done this, using my own EF4 model, with my own implementation of users etc. I used the sample code that came with this video - http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider . BTW if you use that sample code as is, watch out for a couple of typos in stored procedure names!

If you want a custom membership provider, you just need to create a class that inherits MembershipProvider abstract class. Then you will need to implement abstract methods like, ValidateUser, UpdateUser, GetUser etc. You can use EntityFramework while implementing your custom membership provider methods.

Below documents implement custom membership provider with using odbc. You can use your EntityModel instead of odbc.

http://msdn.microsoft.com/en-us/library/44w5aswa.aspx

http://msdn.microsoft.com/en-us/library/6tc47t75.aspx

No, SqlMembership, as well as the other providers in the Sql stack, use stored procedures called directly.

You may, if you would like, build an EF conceptual model on top of your aspnet_db database if you would like to examine or interact with it.

But let me strongly advise that you should treat it as read only unless you know exactly what it is you want to update or delete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM