Search code examples
c#entity-frameworktddsolid-principles

share entity framework interface cross projects


How can I share Entity Framework MyEntitiesDbContext interface cross projects? I would like to follow S.O.L.I.D Principles and use it for testing other projects.

Main problem is sharing model entities with interface and not having loop reference.


Solution

  • How can I share Entity Framework MyEntitiesDbContext interface cross projects? I would like to follow S.O.L.I.D Principles and use it for testing other projects.

    To achieve this, you would need to make EF generated classes to implement interfaces and then use mocks (Rhino Mocks, maybe) to test your code.

    Main problem is sharing model entities with interface and not having loop reference.

    To avoid loop references, you will need the interfaces to be generated and contained in a separate assembly which does not refers back to the EF assembly.

    These are just 2 of the many difficulties that hit people really hard when they try to use EF even though it is now version 6.0

    Fortunately, you can download the T4 files from https://entityinterfacegenerator.codeplex.com/

    They help answer the questions above.