我可以将Entity Framework与ASP.NET成员资格一起使用吗?

时间:2022-04-07 08:09:08

I'm creating (really, re-creating) an app that has existing user and other data in MS-Access databases. The data will be moved to SQL Server, and part of that involves migrating users. I want to use EF to do ORM, and I am pretty sure I know what the data model will be in SQL Server. I am new to EF but not to ASP.NET, and I'd like to take advantage of the Membership features in ASP.NET. I am thinking about several ways to do this and would like some advice. I've done only a little research about this idea thus far, maybe it's been answered elsewhere. So, here goes a cluster of related questions.

我正在创建(实际上,重新创建)一个在MS-Access数据库中具有现有用户和其他数据的应用程序。数据将移至SQL Server,其中一部分涉及迁移用户。我想使用EF来做ORM,我很确定我知道SQL Server中的数据模型是什么。我是EF的新手,但不是ASP.NET的新手,我想利用ASP.NET中的Membership功能。我正在考虑几种方法,并希望得到一些建议。到目前为止,我对这个想法只进行了一些研究,也许它已经在其他地方得到了回答。所以,这里有一组相关的问题。

  1. Can EF work with directly with ASP.NET Membership through some class or namespace that I'm not aware of?

    EF可以通过我不知道的某些类或命名空间直接使用ASP.NET Membership吗?

  2. If I transition users to the Membership system, to align their userids with data in other tables should I create another set of tables for user data atop the aspnet_* tables a la DotNetNuke?

    如果我将用户转换到Membership系统,要将其userid与其他表中的数据对齐,我应该在aspnet_ *表和DotNetNuke上创建另一组用户数据表吗?

  3. I want to avoid a situation where I use the built-in Membership functions for only user authentication and switch over to EF context when I'm working with user-tagged data. Seems clumsy to withdraw user info to bind to a column in a GridView by going into a Membership user for every row, but maybe that's what's needed? Do I need to suck it up and replicate the Membership classes in EF for data retrieval purposes?

    我想避免在我使用用户标记数据时使用内置Membership功能进行用户身份验证并切换到EF上下文的情况。看起来很笨拙,通过进入每一行的成员资格用户来撤销用户信息以绑定到GridView中的列,但也许这就是所需要的?我是否需要将其填充并在EF中复制成员资格类以进行数据检索?

  4. I was thinking of maybe implementing some kind of EF provider for Membership, on the idea that maybe then the provider could sit inside the overall EF data model. Is this crazy talk? (I've never written my own provider before)

    我想可能会为会员实施某种EF提供商,理念是提供商可能会参与整个EF数据模型。这是疯狂的谈话吗? (我以前从未写过自己的提供者)

Feel free to tell me I am not making any sense.

随意告诉我,我没有任何意义。

2 个解决方案

#1


5  

Why not do it the other way around? You can implement your own Membership provider for asp.net, that uses the model you want/need.

为什么不反过来呢?您可以为asp.net实现自己的成员资格提供程序,它使用您想要/需要的模型。

If the features you need aren't a complete match with the built-in asp.net membership implementation, you can just roll your own provider. If you will use just a couple features, you will have to implement just a couple methods (you don't have to fill implementation for all the methods). If you need more features than it supports, using the membership provider might get in your way.

如果您需要的功能与内置的asp.net成员资格实现不完全匹配,您可以直接推送自己的提供商。如果您只使用几个功能,则必须实现几个方法(您不必为所有方法填充实现)。如果您需要的功能多于它支持的功能,使用成员资格提供程序可能会妨碍您。

#2


2  

  1. We do, but we don't map the Membership tables. You shouldn't presume use of the SQL membership provider.
  2. 我们这样做,但是我们没有映射成员资格表。您不应该假定使用SQL成员资格提供程序。
  3. We map the user identity, not the DB id. Subtle, but important. Again, remember that there are other membership providers (e.g., domain auth).
  4. 我们映射用户身份,而不是数据库ID。微妙但重要。同样,请记住,还有其他成员资格提供程序(例如,域身份验证)。
  5. Can you clarify the question? You won't need to replicate all of membership info in your EF model, but you will need a list of known identities.
  6. 你能澄清一下这个问题吗?您不需要复制EF模型中的所有成员资格信息,但您需要一个已知身份列表。
  7. No, not at all crazy, but difficult and probably unnecessary.
  8. 不,不是疯了,但很难,可能没必要。

#1


5  

Why not do it the other way around? You can implement your own Membership provider for asp.net, that uses the model you want/need.

为什么不反过来呢?您可以为asp.net实现自己的成员资格提供程序,它使用您想要/需要的模型。

If the features you need aren't a complete match with the built-in asp.net membership implementation, you can just roll your own provider. If you will use just a couple features, you will have to implement just a couple methods (you don't have to fill implementation for all the methods). If you need more features than it supports, using the membership provider might get in your way.

如果您需要的功能与内置的asp.net成员资格实现不完全匹配,您可以直接推送自己的提供商。如果您只使用几个功能,则必须实现几个方法(您不必为所有方法填充实现)。如果您需要的功能多于它支持的功能,使用成员资格提供程序可能会妨碍您。

#2


2  

  1. We do, but we don't map the Membership tables. You shouldn't presume use of the SQL membership provider.
  2. 我们这样做,但是我们没有映射成员资格表。您不应该假定使用SQL成员资格提供程序。
  3. We map the user identity, not the DB id. Subtle, but important. Again, remember that there are other membership providers (e.g., domain auth).
  4. 我们映射用户身份,而不是数据库ID。微妙但重要。同样,请记住,还有其他成员资格提供程序(例如,域身份验证)。
  5. Can you clarify the question? You won't need to replicate all of membership info in your EF model, but you will need a list of known identities.
  6. 你能澄清一下这个问题吗?您不需要复制EF模型中的所有成员资格信息,但您需要一个已知身份列表。
  7. No, not at all crazy, but difficult and probably unnecessary.
  8. 不,不是疯了,但很难,可能没必要。