views:

257

answers:

2

I have been reading up on porting ASP.NET Membership Provider into .NET 3.5 using LINQ & Entities. However, the DB model that every single sample shows is the newer model while I've inherited a rather old model. Differences:

  • The User Table is split into a pair of User & Membership Tables.
  • All of the tables in the DB are prepended with aspnet_
  • I have Lowered versions of some columns (UserName, Email, etc)

To work with this I have copied the properties from the Membership table into the User table (in the DB this is a 1<->1 relationship, not a 1<->0,1), renamed aspnet_Applications to Application, aspnet_Profiles to Profile, aspnet_Users to User and aspnet_Roles to Role. (See image)

Image
Link to full size image of model

Now, I am running into one of 2 problems when I try to compile.

  1. Using the model in the image I get this error: Problem in Mapping Fragment starting at line 464: EntitySets 'UserSet' and 'aspnet_Membership' are both mapped to table 'aspnet_Membership'. Their Primary Keys may collide.
  2. If I delete the aspnet_Membership table from my model (to handle the above error) I then get: Problem in Mapping Fragment starting at line 384: Column aspnet_Membership.ApplicationId in table aspnet_Membership must be mapped: It has no default value and is not nullable.

My ability to hand edit the backing stores is not the best and I don't want to just hack something in that may break other things. I am looking for suggestions, best practices, etc to handle this.

Note: Moving the data tables themselves is not an option as I cannot replace all the logic in the existing apps. I am building this EF Provider for a new App. Over the next 6 months the old app(s) will migrate bit-by-bit to the new structures.

Note: I added a link just under the image to the full size image for better viewing.

A: 

Keith

Thnis is off the top of my head...

I can't really see your screenshot very well. But I think your first attempt was to have duplicate properties in two entities that point back to the same table. Not legal.

Seems that your 2nd attempt was to do entity splitting. But it loks like you deleted the table definition from the store schema.

I would recommend that you bring that back and do entity splitting (one entity with props from two tables which is doable if table 1 and table 2 share an entity key).

Do you need a pointer to a walkthorugh for that? I'd have to google to find one. I'm sure I"ve got a blog post somewhere.

julie

Julie Lerman
Thanks Julie, a pointer would be great! I am also looking at physically merging the membership table into the users table in the DB and using a couple of triggers to keep the two tables in sync until I can drop the membership table in a few months.
Keith Barrows
I also added a link to the full size image just under the image in my post.
Keith Barrows
A: 

I have got around this by using EF4. EF4 has "FK Associations". This enables you to include the PK/FK (ApplicationId) to the entity and use association you map via the FK.

To do this you will need to add the ApplicationId back to each entity that depends on it and then double click on the association you create between entities and map the two PK/FK's across each other.

Now if they could only add enum support... :/

Damon Stephenson