2

I have an asp.net mvc solution with three projects

  • UI ASP.NET MVC
  • POCO My Domain POCO objects
  • Repository using entity framework and t4 to generate context and POCO classes

I want my UI project to use ViewModels not the POCO classes.

I need to do scaffolding for UI and For Repository independently (i start with repository scaffolding, and then customize some code and then i will scaffold the uicontrollers view viewmodel)

I do Repository scaffolding in the repository project like this : scaffold Repository -ModelType POCO.User -DbContextType Context this is working like a charm

But in In the default mvcscaffolding template when i use the controller scaffolding : scaffold Controller -ModelType POCO.User -ControllerName UsersController -DbContextType Repository.Context -Repository

  • It will detect that the User is already in the context so will skip it (that's good).
  • It Will scaffold wiews using POCO.User as model (that's not what i want, i want it to generate ViewModel Class and use it)
  • It will Generate Repository (that's not good Too since i have already my repository in Repository Project)
  • It will scaffold controller with the repository created and send POCO to the views (not good too)

So i want to do something like this scaffold Controller -ModelType POCO.User -ControllerName UsersController -DbContextType Repository.Context -RepositoryType Repository.UserRepository -GenerateViewModel

that will skipp repository creation but use it in the controllers, that generates ViewModels from the poco and make mappion using automapper for example and use viewmodel in the view.

Any help where to start is apreciated. Thanks

4

1 回答 1

2

您要求做的事情是有道理的,但不是开箱即用的。您可以使用此命令覆盖 T4 模板

> scaffold customTemplate Controller 

但是要跨项目工作,您需要深入了解 powershell 并创建自己的脚手架

> scaffold customScaffolder ViewModel

有关更多信息,请参阅Steven Sanderson 的博客文章。另请参阅此博客文章以获取在 T4 模板中生成 DTO 或 POCO 类的帮助。

于 2013-07-20T20:02:17.660 回答