Scaffold-DbContext

  • 26
  • 0
  • 2024-12-30

Scaffold

https://learn.microsoft.com/zh-tw/ef/core/cli/powershell

資料庫產生 和 實體類型的程式碼 DbContext 。 若要 Scaffold-DbContext 產生實體類型,資料庫資料表必須有主鍵。

Scaffold-DbContext Name="ConnectionString" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -table tableName1,tableName2  -Force

Scaffold-DbContext "data source=ip;initial catalog=database;persist security info=True;user id=account;password=pw;multipleactiveresultsets=True;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -table tableName1,tableName2 -Force

auto generate dbContext Models

https://ithelp.ithome.com.tw/articles/10313137

https://www.uuu.com.tw/Public/content/article/20/20200413.htm