Search code examples
c#asp.net-corerepository-patternscaffolding

scafford auto generate crud repository asp.net5


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

enter image description here


Solution

  • 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.