0

I have conceptual (domain) model which is implemented in different ways in separate databases. For example, inheritance in first db is table per type, second - concrete types are tables, and third - all types properties are merged in one table. Something similar to this: Mapping objects to relational databases

Also, i have two different data access layers (for now) - first is using Entity Framework 5 - Database first approach, and second is ADO.NET dynicamic DAL where i have my DB command factory.

Client application will use these databases and client should choose on startup:

  1. database to connect (connection string) and
  2. data access layer (EF or classic ADO.NET) to consume data.

Depending on client's selection, system should use specified database, and selected DAL.

My questions are:

  1. How can i manage Entity Framework to do a different (dynamicly) mapping details depending on connection string (First connection string - three tables, second two, third one, etc) and mapp them to the same entities?
  2. Is there something else that i should pay attention to, from your experience?
Olinad
  • 187
  • 1
  • 1
  • 13
  • Are you connecting to the same type of database (SQL Server, Oracle, etc.) or are they different technologies. Do they all have the same tables and table design? – Peter Smith Mar 01 '14 at 18:04
  • All databases are on MS SQL Server. Tables are not the same, i have posted link above - for ex. Inheritance is implemented in different ways in each database for the same concecptual - inheritance model. – Olinad Mar 01 '14 at 18:09

1 Answers1

1

This may be too simple. Create a common class that inherits from all three base classes. The database class in the EDMX is always a partial class so create another partial class in the same namespace which is otherwise empty. Use your partial class to generate an interface.

You can the create a domain class:

public class myCommonClass : IDatabaseClass1, DatabaseClass2, DatabaseClass3

and then work with myCommonClass in your application. You can then use Automapper to go between the database classes and the domain classes. Automapper lives here.

It's a Sunday morning so reply may be a little sketchy, and you're probably doing a lot of this anyway but ...

Peter Smith
  • 5,528
  • 8
  • 51
  • 77
  • Peter, thx for reply. I am afraid my question is a bit more sketchy than your reply. :) I already have something similar, and i am trying to avoid Automapper. Right now, my main problem is how to get all three different mappings (from EDMX) use same Entityes - multiple EDMX, one entity. – Olinad Mar 03 '14 at 01:44
  • Hi Olinad, I believe that a single Entity is not possible from multiple sources; your repository layer needs to know which physical database it is talking to. Also, I find Automapper an excellent tool - what are your reservations? – Peter Smith Mar 03 '14 at 18:45
  • Problem with automapper is that it is maybe one more layer and reference to the whole thing, and i thought to make it much more simpler. Peter, please take a look at my new question refering the problem above. http://stackoverflow.com/questions/22137905/entity-framework-inheritance-strategies-one-model-multiple-edmx – Olinad Mar 03 '14 at 22:19