Search code examples
c#architectureentity-framework-4database-first

Where to put generated EF 4 files?


I have 3 csprojs in my web application:

  • UI.Web
  • Bll.Web
  • DAL.Web

UI.Web references Bll.Web and Bll.Web references DAL.Web.

DAL.Web is very simple and only contains methods like:

GetDataTableFromSP
GetScalarFromSP
ExecuteScalarFromSP

I reverse engineered my DB using EF4 and also used the Self-Tracking Entities template. Now I am left with 3 files:

  1. Model.Context.tt
  2. Model.tt
  3. Model.edmx

My question is, within my project structure, where do I put these so that I maintain my n-tier approach?

Thanks!


Solution

  • I would put the T4 template (and therefore the generated entities) in its own Model assembly that is referenced across all the layers. You just need to move the Model.tt to the new assembly, open it in VS using one of the editors so you can see the T4 code. Search for Model.edmx and update the path so it resolves correctly to the physical location on disk of your DAL.Web project that contains the Model.edmx.

    This gives you the ability to rerun the T4 template should the schema/model change but maintain separation of concerns by not having the UI need to take a dependency on the DAL.

    Just found the following that helps explain this here