I am doing refactoring and trying to reuse my models with expressed entities. My application has several assemblies, one of which is my public types (API) and one of which contains vendor implementations (for example, a journal).
I would like to separate the generation of entities and models so that the entities are in the API assembly and the container is in the implementation assembly. Is it possible?
Maybe. Here is how I did it.
- Assembly A
- Database.EDMX
- Models.TT
- Models.cs
- Assembly B
- Database.EDMX ( Added as a link to the real file in assembly A)
- EntityContainer.TT
- EntityContainer.cs
How things are going. These are rough steps:
- Right-click on EDMX in (general API assembly) and add the code generation file.
- Adds TT to the project. Models are called, since it will only contain models.
- TT edited and code creation for entity containers removed
- In assembly B (internal implementations) .EDMA database is added as a reference
- Opened in assembly B, right-click and add the code generation file.
- Adds a TT to project B. EntityContainer is called because it will only contain this.
- Edited TT to do the following
- Remote Object Creation Steps
- Changed the path to Database.EDMX to the relative path pointing to the original copy in A
- Added by
using for my models
Hopefully all of this will compile and work correctly (I'm still far from having everything compiled and tested). It looks good so far.
Additional changes:
In my TT object container, I had to change the definition of EscapeEndTypeName to the following:
string EscapeEndTypeName(AssociationType association, int index, CodeGenerationTools code) { EntityType entity = association.AssociationEndMembers[index] .GetEntityType(); return code.CreateFullName( code.EscapeNamespace(association.NamespaceName), code.Escape(entity)); }
I use association.NamespaceName as it contains the correct namespace from another assembly.
source share