我的電腦突然生病了,所有資料都被洗掉了,無法恢復。
我正在使用 .NET 5 使用 EF core 6 Database first 方法處理幾個專案。
我從 GitHub 克隆了我的專案以取回它們,但不幸的是我沒有資料庫的備份或 SQL 檔案。
有沒有辦法從 .NET 5 專案中的 dbContext 創建資料庫?
uj5u.com熱心網友回復:
我不太明白這個問題,也許是這樣的意思?
//creates an instance of the class where the "database" is
Database db = new Database();
//creates the database if it does not exist
db.Database.EnsureCreated();
uj5u.com熱心網友回復:
你可能應該使用dbContext.Database.EnsureCreated();
有了這個,您的資料庫結構將從模型中重新創建。當然,不會有資料,只有空表、索引等。
uj5u.com熱心網友回復:
您可以使用現有模型重新創建資料庫結構。但是沒有辦法恢復資料
uj5u.com熱心網友回復:
您可以在 startup.cs 檔案或 program.cs '.net core 6' 中使用此代碼
`dbContext.Database.Migrate()`
此行將使用所有未應用于資料庫的遷移更新資料庫
uj5u.com熱心網友回復:
最快的方法是運行這些命令:
添加遷移初始創建
然后:
更新資料庫
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/450024.html
