问题
Hi I am using visual studio 2015, I understand that we can generate crud view controller and action by adding new scafford item. But the code generation is not very usable seem all the data layer is depend on the controller
So Here is my question is tat any way to use scafford generate the code which also generate the repository pattern also? Or any nuget which offer the same feature?
Sorry. I had googling few hour . But still cant find the solution. :(
Thanks
回答1:
I agree, that it's a problem in MVC Core (MVC6). To be able to work with Add Scaffold Controller on have to include some additional packages in "dependencies"
part of project.json
. If you use RC1 then you should include
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
It should be enough to see the Wizard in Visual Studio, which your miss now.
To be able to use in the command line interface for scaffolding (dnx ef dbcontext scaffold ...
for example) you need to add more dependencies
"EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
"EntityFramework.Relational.Design": "7.0.0-rc1-final"
"EntityFramework.Commands": "7.0.0-rc1-final"
add to add "ef": "EntityFramework.Commands"
in "commands"
section of project.json
.
An additional problem bring renaming float of all packages after changing the product name from ASP.NET 5 to ASP.NET Core. The Package "EntityFramework.MicrosoftSqlServer" in version "7.0.0-rc1-final" is renamed to "Microsoft.EntityFrameworkCore.SqlServer" in version "1.0.0-rc2-16811", the package "Microsoft.AspNet.Mvc" in version "6.0.0-rc1-final" is renamed in "Microsoft.AspNetCore.Mvc" in version "1.0.0-rc2-17011" and so on (I used the today's latest builds from https://www.myget.org/F/aspnetcidev/).
I would recommend to stay today on RC1 and to wait for the end of renaming process. I posted the suggestion, which could simplify the migration of existing projects, but the suggestion was not accepted. Microsoft have change the date of RC2 and RTM from February and Q1 to unknown (see TBD on the official roadmap). I hope that the problem will be solved in a short time.
回答2:
So if I understand correctly, you want to generate more than just the controller and view but the available scaffolding items don't support that. If that is the case, please check out my extension T4 Awesome. This is the very reason I built it, I wanted to be able to quickly add new files and folders to my projects and be able to customize those per project. I looked at scaffolding but it did not provide the fast development loop I desired. I have videos on my website that shows how you can create your own scaffolding (multiple items across multiple projects) that will allow you to create almost anything you want using T4 and your own classes, db schema, or db data. It is a completely visual tool, there is no command line support so if you need that it won't help. Also, full disclaimer, I charge for this extension but there is a free community edition that should give you enough of the features to do what you are looking for.
来源:https://stackoverflow.com/questions/35238345/scafford-auto-generate-crud-repository-asp-net5