0

I am writing an application that needs to use ASP.NET MVC scaffolding from DB-first at runtime.

It tests scaffolding from Cli in .NET Core following this link:

https://www.learnentityframeworkcore.com/walkthroughs/existing-database

I know how to do this in .NET Core - but I want in ASP.NET MVC - not .NET Core

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

The EntityFramework DbContext used to be a GUI tool that built the DbContext in a fairly straight forward but multi-step procedure. That was the way DbContext model was built in .NET Framework. That tool was removed in the latest .NET "Core" 5. Now it is a single CLI procedure in NuGet's Package Manager named Scaffold-DbContext. i.e.

Scaffold-DbContext "Server=win2k22.xxxx.xxxx;initial 
catalog=IdentityWorldDb;user 
id=XXX;password=XXXXXXX;MultipleActiveResultSets=True;App=EntityFramework""  
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

That does a nice single step job of creating the DbContext in the Project's Model folder. .NET Core 5's Model folder. I do that as a separate Class project Then if you create a second .NET Core 5 MVC project in the same solution you can reference the DbContext Model in the Class Project. This seems to work perfectly for creating Views in MVC but for some reason it isn't currently working with scaffolding Controllers. Basically EntityFramework seems to be unique between .NET Framework and .NET Core 5 in all respects.

user3594395
  • 181
  • 4
  • 7