Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaffolding a MySQL view using Pomelo and .Net Core 2.1

Apparently, with .Net Core 2.1, views are now supported. I was wondering if it is possible to scaffold a view using Pomelo, and if so, what the syntax is? I tried the "table" syntax with a view but it didnt work:

dotnet ef dbcontext scaffold "Server=myserver.com;Database=myDatabase;User=userame;Password=password;" "Pomelo.EntityFrameworkCore.MySql" -t personsView -o models

It runs, but it only generates a dbContext - it doesn't generate the model.

I'm using Pomelo 2.1.1 and Visual Studio 2017 (15.7.5). My project is a .Net Core 2.1 Web API. On the back end, I have MySQL Server 5.6.30.

like image 339
Fabricio Rodriguez Avatar asked Jan 02 '23 06:01

Fabricio Rodriguez


1 Answers

Using Pomelo, you can use the following command (within the Package Manager Console) to generate the models as well as the context class:

Scaffold-DbContext [CONNECTION_STRING] Pomelo.EntityFrameworkCore.MySql -OutputDir [OUTPUT DIRECTORY] -Context [NAME OF CONTEXT CLASS] -f

like image 71
spiros Avatar answered Jan 05 '23 14:01

spiros