I have a MySQL database sitting in Amazon Cloud (RDS). It is a tiny database with only one table.

I want to use EF Core, Database First. I know that the Pomelo.EntityFrameworkCore.MySql package is popular, but I cannot see any information on how to achieve a scaffolding of the Db Context via that package.

I followed the instructions here whilst replacing MySql.Data.EntityFrameworkCore.Design with Pomelo.EntityFrameworkCore.MySql but when I ran the command below in Package Manager Console:

Scaffold-DbContext ";database=TestDb;uid=blah;pwd=blah;" Pomelo.EntityFrameworkCore.MySql -OutputDir Models -f

I just got the error:

The specified framework version '2.0' could not be parsed

What am I missing? Here's how my dummy solution looks

screenshot of solution

3/29/2018 7:26:47 AM

Accepted Answer

You need to have these references in your .csproj. Of course, the versions might vary.

    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0-preview2-final" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />

    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.1.0-preview1-final" />

Note: I had to manually add DotNetCliToolReference to Microsoft.EntityFrameworkCore.Tools.DotNet (not via Manage Nuget Packages view in the Visual Studio)

4/13/2018 6:48:55 PM

Popular Answer

In 2020 with .net core 3 released a lot of things changed, this is what working as of now :)

Make sure you have all these packages

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />

Now dotnet ef is a global tool that needs to be installed, reference

dotnet tool install --global dotnet-ef

Then run this command, reference

dotnet ef dbcontext scaffold "Server=localhost;Database=ef;User=root;Password=123456;TreatTinyAsBoolean=true;" "Pomelo.EntityFrameworkCore.MySql"

For scaffolding in a different path, you can use --output-dir

dotnet ef dbcontext scaffold server=localhost;port=3306;database=palle2patnam;uid=root;password=password" "Pomelo.EntityFrameworkCore.MySql" --output-dir Models

For forcing to get new fields from database u can add --force

dotnet ef dbcontext scaffold "server=localhost;port=3306;database=palle2patnam;uid=root;password=password" "Pomelo.EntityFrameworkCore.MySql" --output-dir Models --force

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow