How to use EF DbFirst with MySQL in .NET Core?
Asked Answered
F

1

6

I try to use EF with MySQL in my project. And I add:

MySql.Data.EntityFrameworkCore
MySql.Data.EntityFrameworkCore.Design

into my project.json but the tools section of project.json is empty. When I run:

Scaffold-DbContext "myconnectionstr" MySql.Data.EntityFrameworkCore -OutputDir Models -StartupProject "myproject"

The console shows me an error:

Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly MySql.Data.EntityFrameworkCore

Floorman answered 1/3, 2017 at 6:59 Comment(3)
Did this work? Im stuck at the same thing.Audraaudras
@Audraaudras unlucky,i worded with code first at last.Floorman
some times clearing the data from "temp" directory would solve some of the issues, C:\Users\<logonuser>\AppData\Local\Temp\Ciprian
A
5

It seems that "official" provider MySql.Data.EntityFrameworkCore 7.0.7-m61 still unsupports scaffolding. However, it works fine with Pomelo.EntityFrameworkCore.MySql free community provider:

dotnet ef dbcontext scaffold "Host=localhost;Port=3306;Database=foodb;Username=root;Password=mysql" ^
    Pomelo.EntityFrameworkCore.MySql ^
    --force ^
    --context "FooContext" ^
    --output-dir "Entities" ^
    --verbose

Our csproj (Visual Studio 2017):

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>    
        <TargetFramework>netcoreapp1.1</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
        <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.2-preview-10036" />
        <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2-preview-10036" />

        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
    </ItemGroup>
</Project>
Abnegate answered 23/4, 2017 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.