Entity Framework, doubts with the structure of the solution (app.config and package.config)

2

I started a solution with Entity Framework code-first. In the structure of the solution, I have separated the domains from the other EF files (context, etc.). That is, the domains were in a separate project. However, for me to be able to make use of the EF data annotations, I needed to reference EF in the domains design as well. That way, I have the EF referenced in two places, in the domains project and in the project where the remaining EF files are, so I end up with two files app.config and two package.config . Is it necessary for each project that references EF to have its own app.confg and package.config files?

    
asked by anonymous 23.05.2016 / 23:43

1 answer

2

Some remarks before the answer:

  • The Entity Framework is already an ORM. You do not need to create a project to envelop this;
  • You do not need to separate the domain from the ORM layer. The correct is the context and the entities stay in the same project;
  • You are putting an unnecessary level of complexity in your project. A Model is not a DTO because it is not anemic. As I see it, you're experiencing in the same errors as this question here ;
  • In DataTransferObjects (which, by good practices, should be discarded from your solution), the correct thing would be to group your entities by namespace through a directory.
  • Let's answer:

      

    Is it necessary for each project that references EF to have its own files app.config and package.config ?

    Yes, it is. I explain:

    app.config indicates to the Entity Framework which data providers will be used. If there is a context in the layer, and the layer works independently of the Web project, configuration is required.

    To prove this, try running a migration using your isolated domain layer as your initial project.

    package.config tells NuGet what you are using from external dependency in your Class Library . Each component of the solution has its own packages.config . An example of this is that you will not use Web dependencies in a Class Library domain, and will not use EF in a Web project that has no descriptive data access.

        
    23.05.2016 / 23:50