简体   繁体   English

Asp.Net成员 - 实体框架4中的提供商

[英]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. 我有一个使用ASP.NET Membership,Entity Framework 4和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? 我想知道如果使用ASP.NET成员资格,将使用Entity Framework传递与数据库的交互?

Thanks for your help! 谢谢你的帮助!

Upvoted on Musa's answer to remove the negative. 对Musa的回答进行了评价,以消除负面影响。 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. 他是正确的,没有与框架一起提供的EF4特定提供程序,但您可以构建自己的。

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. 实现这一点的方法确实是通过继承MembershipProvider并实现抽象方法。

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. 一旦你完成了这个,你就可以为用户做任何你想要的事情,而不是生活在打破你默认获得的SQLMembership表和存储过程的恐惧 - 我不喜欢使用,因为它们很难看。

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 . 我刚刚完成了这个,使用我自己的EF4模型,我自己的用户实现等。我使用了这个视频附带的示例代码 - 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. 如果需要自定义成员资格提供程序,则只需创建一个继承MembershipProvider抽象类的类。 Then you will need to implement abstract methods like, ValidateUser, UpdateUser, GetUser etc. You can use EntityFramework while implementing your custom membership provider methods. 然后,您需要实现抽象方法,如ValidateUser,UpdateUser,GetUser等。您可以在实现自定义成员资格提供程序方法时使用EntityFramework。

Below documents implement custom membership provider with using odbc. 下面的文档使用odbc实现自定义成员资格提供程序。 You can use your EntityModel instead of odbc. 您可以使用EntityModel而不是odbc。

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

http://msdn.microsoft.com/en-us/library/6tc47t75.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. 不,SqlMembership以及Sql堆栈中的其他提供程序使用直接调用的存储过程。

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. 如果您愿意,可以在aspnet_db数据库之上构建一个EF概念模型,如果您想检查它或与之交互。

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. 但是,我强烈建议您将其视为只读,除非您确切知道要更新或删除的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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