How can I manage the two following tables in Entity Framework :
Order
- OrderId
- ProductId
- Date
and
OrderArchive
- OrderId
- ProductId
- Date
In this schema orders are periodically transfered from the table Order to the table OrderArchive…
Neither Table Per Type nor Table Per Hierarchy seems to fit my needs… I want to share the same methods for both object types.
Note that I cannot change the database schema.
Thank you for your help.
Well, if you can’t change the Database schema, … you’ve got a huge limitation !
If you could change that, I would do an (abstract)
OrderBaseclass, with the common Properties and Methods, and makeOrderandOrderArchiveinherit from it.But if you can’t, the only thing I see (someone has maybe a better idea) would be
create an interface IOrder
make
OrderandOrderArchiveimplementIOrder(that won’t change Database schema)and create an helper class with common methods.
But of course, inheritance would be much cleaner, in this case.
EDIT
Maybe look for Table per Concrete Type : you might be able to inherit from an abstract class, which wouldn’t be mapped in db, and your Database wouldn’t be changed.
With Code First, you would have to do
but I don’t know what you’re using (CodeFirst, ModelFirst, DatabaseFirst) ?