views:

32

answers:

1

In my previous question, I asked how I would design the database schema where 1 table (Comments) would reference 2 tables (Question and Answer). I was given the response to use one table for Question and Answer (SO uses Posts).

Now I am in Entity Framework 4. How can I set it up so that this one table (Posts) maps to 2 objects (Question, Answer)? Should I do this in my data layer, or do it in Business Layer?

I was thinking I should do the conversion in my data layer, so that I don't select too many unneeded columns from the database.

+1  A: 

Make single parent entity called Post and derive two entities (Question, Answer) from the Post. Your Post table has to have single column which will differ the type of post (question or answer). Then create table per hiearchy mapping with that column as discriminator.

Ladislav Mrnka
Thanks, I struggled with this last night. I just don't understand why the conditional column (PersonCategory in the example) cannot be anywhere in the EDMX file. Took me 2 hours to figure that out.
Martin
Because it is not data column, it is column which differs your types (Question, Answer).
Ladislav Mrnka