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:
- Model.Context.tt
- Model.tt
- Model.edmx
My questio开发者_运维技巧n is, within my project structure, where do I put these so that I maintain my n-tier approach?
Thanks!
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
It's all a matter of personal preference.
For example I always put those files and the model in the DAL aspect of my application. But I also need access to the generated entities, such as Student, Grade or StaffType. So I reference DAL from the BRL.
And in the UI I also need to be aware of the generated entities because usually I give a form an Entity and it populates the form fields from that object. So I also reference the BRL from the UI.
精彩评论