samedi 25 novembre 2017

Entity Framework, Repository Pattern and 2 DBs

I am working on an app that works with 2 DBs. I want to use EF, Repository and UnitOfWork Pattern. I am learning clean code principles and design patterns, so want to have some feedback,since although I (think) understand the main ideas, I'm struggling a bit in the implementation. I have readed a lot of answers and articles but still not being able to bring the ideas to my specific problems completely.

I have 2 DBs.

  1. Legacy-DB of our ERP-System. Only Read-access (aka ERP-DB). From this DB I have to take all the Info I need.
  2. Project-DB. Needs to be created and for it I have no restrictions. (aka Project-DB)

So first if I understood it right for the ERP-DB I should use the DBFirst Approach since I can't modify the DB and for the Project DB I could use anyone, being CodeFirst maybe the best approach (Since I am trying to do DDD) so I can first design my domain model and then define what will be persisted.

Now 1 question:

  • The ERP-DB is very "generic" and has for example a table "articles". Here you find any type of article we have, from complete build devices to assembly pieces. So with DBFirst the EF generates for it an entity called "Articles". But I don't want to use such a class in my domain model, I would like better classes like transmitter, termometer, measureCell etc. They are "specific" articles. So I need to map Articles to the different domain objects.

    • Do I need to do it manualy or can EF does it for me in DBFirst?
    • If manually, should I create a Repository for each domain object and put the map logic in it? Or should I create 2 Repositories, 1 for data entities and 1 for domain objects and then where to put the map logic?
    • Some specific articles contains more than one article, i.e. a transmitter has a measureCell, both entities are in the same articles table. So here should my TransmitterRepository have a method, that knows how to retrieve a transmitter or where should I put this logic?

Now, regarding the project-DB, I could use CodeFirst to focus on my domain model and define what needs to be persisted. So if I choose this approach and understand it right I could map here directly my data entities to my domain objects. But I dont understand it completely since for me I am just putting the same logic somewehere else, instead of having it in the repos I have it directly in my objects, but what do I "win" there?

Aucun commentaire:

Enregistrer un commentaire