views:

2339

answers:

2

Hi, I'm using the TPH (Table per Hierarchy) technique to map a set of entities.

DB Schema: UserGroupLabelSpreads table having a "UserId", "GroupId" and "LabelId" nullable fields with some additional common fields.

DAL Objects: - UserGroupLabelSpread abstract class. - UserSpread with a discriminator having only non-null UserId. - GroupSpread with a discriminator having only non-null GroupId. - LabelSpread with a discriminator having only non-null LabelId.

I've managed to get this thing to work, but when I try to connect the UserSpread entity to an existing "User" entity, I'm getting the following error: Error 1 Error 3034: Problem in Mapping Fragments starting at lines 487, 554: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.

I've digged around to understand that the problem is that I'm mapping the UserId column twice: once for the discriminator condition and second for the association.

Am I right with my assumption? -Can I get this thing to work?

Thanks, Nir.

+1  A: 

There is an updated version of EDM Generator which should be able to help you. You can use it to generate, validate and more. Sorry, got the wrong link. Here is the one to v2. I believe I've had this issue. If I am not mistaken it was due to me mapping the forreign keys wrong. I was however using beta 1 of EF4 at that time and some of the messages was wrong due to the proxies. Check your forreign keys. Blog.Id ---> Blog_id was my issue. I had Blog.Id --> Blog.Id and then BlogEntry.Id ----> Blog.Blog_Id which of course doesn't work but the designer is kind of unforgiving when it comes to mapping keys.

mhenrixon
A: 

Thanks for the answer, I'll check it out. I think I need to rephrase my question: Can I have a derived entity (which, of course, has a mapped field for the condition) AND an association using this same field exactly? In my scenario, I have the "UserSpread" derived entity, for example, which have a discriminator on the UserId field AND an association to the "User" entity (Users table in the database). Is that possible to achieve? Thanks, Nir.

You can't map the database column twice. If it is an association it will get saved but you have to load the related side to use it.Either it is a scalar property or a navigational property. Can't be both.
mhenrixon