我正在使用MySQL DB在.Net Core 2.0中开发WEB API。我正在尝试搭建MySQL DB。我跟着This link (MySQL Official Site)但是当我解雇脚手架命令时我得到了错误,我在下面提到过,如果我做错了什么,请告诉我。 脚手架命令(在程序包管理器控制台中触发)
Scaffold-DbContext "server=localhost;port=3306;user=root;password=darshan7826;database=sakila" MySql.Data.EntityFrameworkCore -OutputDir sakila -f
执行上述命令时出错
System.NotImplementedException: The method or operation is not implemented.
at MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.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)
The method or operation is not implemented.
答案 0 :(得分:7)
答案 1 :(得分:4)
查看MySQL Connector for .Net的官方源代码,您可以看到它尚未完成,原因如下:
public DatabaseModel Create(string connectionString,
IEnumerable<string> tables, IEnumerable<string> schemas)
{
throw new NotImplementedException();
}
您可能想要在official bug tracker上打开错误报告。
或者,似乎有一个更新的测试版本,您可以尝试。 https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/8.0.9-dmr
答案 2 :(得分:0)
您应该运行此命令(从Package-Manager-Console):
Scaffold-DbContext "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
MySql.Data.EntityFrameworkCore -OutputDir Models
或使用:
dotnet ef dbcontext scaffold
注意:您应该位于已添加MySql.Data.EntityFrameworkCore
NuGet软件包的项目中。