1

I am using Entity Framework 6 and database-first to generate my table entities. Is it possible to make the entities private?

This is my project setup:

  • Project.Core
    • DatabaseFirstContext.edmx
    • Service.cs
    • DomainModel.cs
    • Repository.cs
  • Project.Web
    • HomeController.cs

I would like my Project.Web to be able to see my DomainModel.cs but not the entities which the DatabaseFirstContext.edmx generates. The reason I would like to keep the EF6 generated entities in the Project.Core is because it is one less layer of mappings. This way the Service.cs can work directly with the generated entities. But I would like to prevent the Project.Core from exposing the generated entities to other projects and prevent other developers from exposing them.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Evan Larsen
  • 9,935
  • 4
  • 46
  • 60

1 Answers1

0

To me, this is weird to hide the entities. Anyways, you need T4 Templates.

A tutorial: https://www.dotnettricks.com/learn/entityframework/using-t4-templates-in-entity-framework

See also: https://learn.microsoft.com/en-us/ef/ef6/modeling/designer/codegen/

Alireza
  • 10,237
  • 6
  • 43
  • 59