开发者

Reorganizing codes after generating it using ADO.NET DbContext Generator

Suppo开发者_Python百科se I am creating a application using the sample Northwind database using asp.net mvc 3 and entity framework database first approach. For that I am opening a new asp.net mvc 3 project and then adding a ado.net entity data model. I am generating it from the existing database as it is already created. After that I am using the ado.net DbContext generator to generate codes for me. These includes all the models and the DbContext file(in this case NorthwindContext).

Now the problem that I am facing is in reorganizing the code. All the models should be placed in the Model folder of the project. Even if i generate the codes in the Model folder the NorthwindContext class is also generated in it. That is under the NorthwindContext.tt file a NorthwindContext.cs is generated. This file should reamin in the DAL folder as I will use it for accessing the data. Now if i just drag an drop it into the DAL folder the code generation stops automatically(no code remains in the NorthwindContext.cs file). Any idea how i can resolve this problem?????


There are a few hoops you need to jump through to get this setup.

You should have two T4 templates generated, one for the model classes and one for the context. Move the T4 template for the model to your model assembly then open it in Visual Studio and update the file path back to the edmx in your data access assembly. Edit the context T4 in the data access assembly to emit a using statement for the model namespace. Finally add a reference to your model assembly in the data access assembly.

Whenever you want to regen the classes right click in VS and select Run Custom Tool for both the Context and Model T4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜