[英]Is OR/M available in .NET core web API project?
In ASP.NET Framework projects one could right click the project and add a ADO.NET Entity Data Model using an existing database.在 ASP.NET Framework 项目中,可以右键单击该项目并使用现有数据库添加 ADO.NET 实体数据模型。 This would create classes and properties from database's tables and columns.
这将从数据库的表和列创建类和属性。
But this option is missing from ASP.NET Core API web application project.但是 ASP.NET Core API Web 应用程序项目中缺少此选项。 What can I use to create these classes from existing SQL Server database, or is that not possible?
我可以用什么来从现有的 SQL Server 数据库创建这些类,或者这是不可能的?
Try to execute the following command under your project folder:尝试在您的项目文件夹下执行以下命令:
$ dotnet ef dbcontext scaffold "Server=....." Microsoft.EntityFrameworkCore.SqlServe
r -o Models
And fill the string Server=.....
with your database connection string.并用您的数据库连接字符串填充字符串
Server=.....
Make sure that you can connect to this database successfully.确保您可以成功连接到此数据库。
And EF will try to build models from the database. EF 将尝试从数据库构建模型。
Reference: https://anduin.aiursoft.com/post/2020/2/13/creating-a-model-for-an-existing-database-in-entity-framework-core参考: https : //anduin.aiursoft.com/post/2020/2/13/creating-a-model-for-an-existing-database-in-entity-framework-core
This worked这有效
In Package Manager Console:在包管理器控制台中:
Install-Package Microsoft.EntityFrameworkCore.Tools
scaffold-dbcontext "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -outputdir Models -Table table1,table2
If you get an error that "The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet...", see this question: The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet, function, script file, or operable program如果您收到“未将术语 'scaffold-dbcontext' 识别为 cmdlet 的名称...”的错误,请参阅此问题:术语 'scaffold-dbcontext' 未识别为 cmdlet 的名称,函数、脚本文件或可运行的程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.