views:

268

answers:

3

I'm mapping a set of tables that share a common set of fields:

alt text

So as you can see I'm using a table-per-concrete-type strategy to map the inheritance.

But...

I have not could to relate them to an abstract type containing these common properties.

It's possible to do it using EF?


BONUS: The only non documented Entity Data Model Mapping Scenario is Table-per-concrete-type inheritance http://msdn.microsoft.com/en-us/library/cc716779.aspx : P

+1  A: 

Why not fix the table design?!

reinierpost
Hi Reinier! thanks for your suggestion : ). but actually it would result very expensive (there are ~150 tables in the project) so I would consider it in the next iteration. right now we prefer to implement it this way, avoiding a huge-uber-refactor. also there are many tradeoffs between strategies, this one is good at perfomance (avoid lots of joins against a central table). thanks again :).
SDReyes
BTW I'm supposing you are talking about a Table-per-type inheritance strategy. (offtopic) : )
SDReyes
Sure, you do save on joins. But I don't know how to help you, sorry.
reinierpost
+2  A: 
SDReyes
A: 

I have achieved this exact scenario today. The designer does not seem to do it properly, but here is how I did it by modifying the EDMX: -

  1. In the base class, put all your shared properties e.g modified date and modified by. You can do this in the CSDL section. Do not put any conditions on the CSDL.
  2. In the C-S mapping content, put the mappings of your fields in. Obviously you need to map on both child entities the shared properties to the physical DB columns.
  3. Put a condition on each table where the PK column e.g. Id sets IsNull=false.

If you then reopen the designer, you should see that the shared fields are in the base class, and the only fields that appear on the derived types (in the Column Mappings area) will be the unique columns.

At least, this worked for me :-)

Isaac Abraham