Entity Framework Core Migration

Create an Initial Migration


dotnet ef migrations add InitialCreate

Examine Up and Down methods

使用 migrations add 的時候, EF 會幫你把資料庫的表轉換成 code 並且存在 Migrations 的資料夾裡面, 檔名會是由 timestamp 和 migration name 所產生, 在 file 裡面 Up method 會根據資料庫的 table 創建一個 Data Model Entity Sets, 反之, Down method 會刪除資料庫裡面的 table
如果在 table 已經存在的情況下去 create 第一次的 migration, 可以用來 create database 的 code 會產生出來, 但是這個 code 並不會執行, 因為 database 裡面已經有相對應的 table 了

留言

這個網誌中的熱門文章

ASP.NET Web API - DTOs

Scaffold Identity into the Current Project

Passing data from controller to the view