views:

1035

answers:

2

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.

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

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?

3) I want to avoid a situation where I use the builtin 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?

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)

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

A: 
  1. We do, but we don't map the Membership tables. You shouldn't presume use of the SQL membership provider.
  2. We map the user identity, not the DB id. Subtle, but important. Again, remember that there are other membership providers (e.g., domain auth).
  3. 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.
  4. No, not at all crazy, but difficult and probably unnecessary.
Craig Stuntz
Clarification on #3: Say I want to databind records from a table of user-entered data, and one of the fields I want to show is the user's email which of course isn't in that table. Do I need EF User classes with Email properties? Do I have to iterate through each row and call Membership.GetUser?
oasasaurus
If you want a solution which will work with any membership provider, whether SQL-based or not, then you need to either do what you suggest or replicate the membership into your database, and map the replicated table.
Craig Stuntz
+1  A: 

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.

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.

eglasius
If I do that, can it be neatly folded in with the EF classes/EDM? I guess what I'm asking is, do you think I could roll a provider as though EF was the backend instead of the database? Also, is it the database layer or the web/UI layer that does stuff like hashing?
oasasaurus
yes, you implement the methods related to the features you need, with pretty much any code you want inside it i.e. ado.net, linq2sql, EF, [insert any ORM], call a web service, whatever you need
eglasius
It is meant to be the web UI layer, not that it actually forces you to that. The base MembershipProvider class has some methods to encrypt/decrypt, although I must say I haven't used them on my custom provider.
eglasius
...and then abandon the whole thing when you have to use domain/Kerberos/OpenID/Live/etc. authentication. Like I say, don't presume that membership will always be in a DB, because it simply won't.
Craig Stuntz