views:

14

answers:

1

have two tables in database.

They have completely the same columns, only the difference between them - they have different names.

Lets say i have TableSea with column s Id and Name and TableOcean with the same columns Id and Name.

I want to use EF 4 to be able CRUD operations, i am also want to use stored procs mapping for insert update and delete operations.

I am already created POCO entity for first table and i did create stored procedures and map them to entity model. All working well.

How make it work with two tables without create a new entity for second table?

A: 

AFAIK, you can't, and you definitely shouldn't!

If you have two identical database tables, then this means one of the following:

  1. The two tables mirror closely related concepts (like Sea and Ocean in your example).
  2. The two tables mirror different concepts which only accidentally have the same properties.

Depending on which scenario is closer to reality, you have these two design options:

  1. Merge the two tables and add a Type property (column), then map it to one entity type. You might have different subclasses to differentiate between types, or you may go with an additional Type property - whichever fits better for you.
  2. Have two tables. Which means: there are two different concepts. Consequently, this has to be mirrored by two different entities in the business model.

In any case, having an entity table in the database means having an entity class in the business model. If there's no such 1:1 - mapping, then clearly something is wrong with the design!

Thomas

Thomas Weller