Entity Framework contains T4 templates that can generate C# classes for database entities. However, these T4 templates don’t generate separated interfaces for the generated classes. This makes it difficult (if not impossible) to apply IoC and unit
Entity Interface Generator
This project contains customized T4 templates which can generate interfaces and attributes for the DbContext class and entity classes.
What are the benefits?
- Enable IoC and
Unit Tests by generating separated interfaces for entities.
The interfaces could be generated in a separated and independent assembly to be redistributed without the need of the actual data access assembly. This cannot be done with EF 6.0 because of 2 exceptions which have been addressed in version
22.214.171.124 and 126.96.36.199.
If you must have separated assemblies, please download versions prior to 188.8.131.52 and use EF 5.0. The breaking changes are introduced only in EF 6.0.
- Generic unit test to smoke test the generated model by getting top 1 of every table.
All what you need are the T4 files. Copy them into your data access project and watch for the generated content. Then, you can tweak the T4 files to adapt to your project’s convention and needs.
Generate interfaces for DbContext and entity classes.
Generate attributes for DbContext and entity classes.
Conditionally generate interfaces for entity classes and interfaces matching by regular expressions.
Conditionally generate attributes for entity classes and interfaces matching by regular expressions.
Critical Bug Fix:
Entity Type Not Recognized By Entity Framework
Critical Bug Fix:
Navigation properties must implement ICollection<T> in order for Entity Framework to be able to track changes in collections
Conditionally generate interfaces for entity classes and interfaces based on their properties.
Conditionally generate attributes for entity classes and interfaces based on their properties.
Generate mocks and stubs for faking DbContext.
Generate generic repository interfaces for CRUD.
Generate generic repository interfaces for direct linking entities (one to many).
Generate generic repository interfaces for indirect linking entities (many to many relationship).
Generate unit tests for repositories.
Generate Web API Controllers.
Additional works are published on my blog