問題描述
到 VS 2019,我創(chuàng)建了一個(gè) API 項(xiàng)目(數(shù)據(jù)庫優(yōu)先),一切正常,現(xiàn)在我對(duì)數(shù)據(jù)庫進(jìn)行了一些更改,例如添加新表和一些屬性以及修改其他人的數(shù)據(jù)類型等等..,問題是如何更新模型以匹配 SQL 中的數(shù)據(jù)庫?
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?
這是我的項(xiàng)目的屏幕截圖:
this is a screenshot for my project:
推薦答案
嘗試通過帶有Force"參數(shù)的 Scaffold-DbContext 重新創(chuàng)建模型.
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
這篇關(guān)于如何從 ASP.NET Core 實(shí)體框架中的數(shù)據(jù)庫更新 VS 2019 中的模型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!