EntityFrameworkCore
基於現有數據庫
PM> Scaffold-DbContext
-Connection "Server=IP地址;UID=用戶名;PWD=密碼;Database=數據庫名"
-Provider Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models
添加(localdb)MSSQLLocalDB
PM> Scaffold-DbContext
-Connection "Server=(localdb)\MSSQLLocalDB;AttachDbFileName=F:\localdb\DTcmsdb4.mdf"
-Provider Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models
異常狀況
- 出現異常
可經過移除~~Trusted_Connection=True;
~~解決,但更安全的作法是完善數據庫安全.
參考文檔
- https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db