如何从 ASP.NET Core 实体框架中的数据库更新 VS 2019 中的模型

到 VS 2019,我创建了一个 API 项目(数据库优先),一切正常,现在我对数据库进行了一些更改,例如添加新表和一些属性以及修改其他人的数据类型等等..,问题是如何更新模型以匹配 SQL 中的数据库?

By VS 2019, I created an API project (database first), everything it's working well, now I made some changes in the database like add new tables and some property and modify data type for others and so on.., the question is how to update models to match the database in SQL?

这是我的项目的屏幕截图:

this is a screenshot for my project:

推荐答案

尝试通过带有Force"参数的 Scaffold-DbContext 重新创建模型.

Try to recreate your models via Scaffold-DbContext with "Force" param.

Scaffold-DbContext "Data Source=yoursource;Initial Catalog=yourdb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -Force

相关文章