每个人。我一直在尝试使用 EntityFrameworkCore 开发简单的启动 AspNetCore 应用程序,以连接和使用 MS SQL 服务器数据库。并通过 Rider IDE、数据库客户端工具 (DBeaver) 和 dotnet 命令行界面 (dotnet ef) 管理所有这些。我正在使用数据库优先方法(在 mssql 服务器上创建数据库,用表填充它,然后基于表构建模型)。我的逐步行动:
1)为我在 Ubuntu 18.04 上工作的机器安装和设置 mssql 服务器。安装命令行工具“SQLCMD”。/// 指南链接 - https://docs.microsoft.com/en-gb/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15
2)本地连接到我的 MSSQLServer 实例。 sqlcmd -S localhost -U SA -P 'MyPasswd'
3) 使用 Transact-SQL 创建的数据库并安装 DB 客户端 (DBeaver) 来快速管理我现在和将来的数据库。
下一步,正如我所想的那样,是使用有关将我的 Web 应用程序连接到此处找到的数据库的教程https://blog.jetbrains.com/dotnet/2017/08/09/running-entity-framework-core-commands-骑手/和这里https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx
我的 ASP.NET Core 项目的包引用:
在输入 CLI 命令 dotnet ef dbcontext scaffold "Server=localhost;Database=WebAppDB;Integrated Security=true;" 后 Microsoft.EntityFrameworkCore.SqlServer -c RsvpContext(构建“RsvpContext”上下文以连接到我的数据库 WebAppDB。)
我看到我看到的:
Build started...
Build succeeded.
Microsoft.Data.SqlClient.SqlException …
Run Code Online (Sandbox Code Playgroud)