我尝试使用现有数据库创建EntityFramework Core的模型(doc:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html),但是我有错误。
当我尝试程序包管理器方法时,出现错误:
The term "MY_DATABASE_NAME" is not recognize as a valid command applet [...]
这是我执行的命令:
Scaffold-DbContext "'MY_CONNECTION_STRING'" Microsoft.EntityFrameworkCore.SqlServer -outputDir MY_PATH -verbose
当我尝试命令提示符方法时,出现此错误:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Tools.DispatchCommand.<>c__DisplayClass2_0.<Create>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Object reference not set to an instance of an object.
这是我执行的命令:
dotnet ef dbcontext scaffold "'MY_CONNECTION_STRING'" Microsoft.EntityFrameworkCore.SqlServer -outputDir MY_PATH -verbose
在此问题之前,我查了一下:
答案 0 :(得分:1)
成功使用命令提示符:
命令:
dotnet ef dbcontext scaffold "MY_CONNECTION_STRING" Microsoft.EntityFrameworkCore.SqlServer -o MY_ABSOLUTE_PATH