用Scaffold命令生成数据库实体类,新建个asp.net core 2.2 webapi项目,在.net core 2.2下是好的,能生成实体类。再新建asp.net core 3.0 webapi项目,关联的驱动和组件都升级到3.0 预览版,同样的Scaffold命令就报错了,不知道问题再哪里?目前就现在2.2里生成实体类,在复制到3.0的项目中用。
PM> Scaffold-DbContext -Force "Data Source=xx;Database=cloud;User Id=xx;Password=xx;CharSet=utf8;port=xx" MySql.Data.EntityFrameworkCore -OutputDir Models -Context MySqlContext
System.TypeLoadException: Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.17.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
at MySql.Data.EntityFrameworkCore.Design.Internal.MySQLDesignTimeServices.ConfigureDesignTimeServices(IServiceCollection serviceCollection)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureDesignTimeServices(Type designTimeServicesType, IServiceCollection services)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable
1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable
1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.17.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
PM> Scaffold-DbContext -Force "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = xx)(PORT=xx))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =xx)));User Id=xx;Password=xx;" Oracle.EntityFrameworkCore -OutputDir DataModels -Context MyDbContext -Schemas xx
System.TypeLoadException: Method 'Create' in type 'Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.
at Oracle.EntityFrameworkCore.Design.Internal.OracleDesignTimeServices.ConfigureDesignTimeServices(IServiceCollection serviceCollection)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureDesignTimeServices(Type designTimeServicesType, IServiceCollection services)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable
1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable
1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method 'Create' in type 'Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.
Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
--mysql (replace sensitive information to xx)
Scaffold-DbContext -Force "Data Source=xx;Database=cloud;User Id=xx;Password=xx;CharSet=utf8;port=xx" MySql.Data.EntityFrameworkCore -OutputDir Models -Context MySqlContext
--oracle (replace sensitive information to xx)
Scaffold-DbContext -Force "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = xx)(PORT=xx))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =xx)));User Id=xx;Password=xx;" Oracle.EntityFrameworkCore -OutputDir DataModels -Context MyDbContext -Schemas xx
Further technical details
$ dotnet --info
.NET Core SDK (global.json):
Version: 3.0.100-preview8-013656
Commit: 8bf06ffc8d
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview8-013656
Host (useful for support):
Version: 3.0.0-preview8-28405-07
Commit: d01b2fb7bc
.NET Core SDKs installed:
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
2.2.401 [C:\Program Files\dotnet\sdk]
3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]
IDE: (Visual Studio Community 2019 16.2.3)
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.0-rc1" />
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Dapper" Version="2.0.4" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0-preview8.19405.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview8.19405.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0-preview8.19405.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview8.19405.11"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.0.0-preview8.19405.4" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.0.0-preview8.19405.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview8-19413-06" />
<PackageReference Include="MySql.Data" Version="8.0.17" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.17" />
<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.17" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3-beta1" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="2.19.30" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.31" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc8" />
我之前也遇到过同样的问题,应该是 mysql 的 ef 库还没有更新到 .NET Core 3.0 的原因。