LoginSignup
2
3

More than 1 year has passed since last update.

dotnet ef コマンド

Posted at

参考サイト

コマンド一覧

dotnet efツールのインストール

# ツールのインストール
$ dotnet tool install --global dotnet-ef

# ツールのアップデート
$ dotnet tool update --global dotnet-ef

# 特定のプロジェクトでツールを使用するには、その前に Microsoft.EntityFrameworkCore.Design パッケージを追加する必要がある
$ dotnet add package Microsoft.EntityFrameworkCore.Design

dotnet ef

インストールの確認。

$ dotnet ef

dotnet ef database drop

データベースを削除する。

$ dotnet ef database drop

dotnet ef database update

データベースをアップデートする。

# データベースをマイグレーションファイルを使用してアップデート
$ dotnet ef database update
# 移行名を使用
$ dotnet ef database update InitialCreate
# 移行IDと指定された接続を使用します。
$ dotnet ef database update 20180904195021_InitialCreate -connection your_connection_string

dotnet ef dbcontext info

DbContext 型に関する情報を取得する。

$ dotnet ef dbcontext info

dotnet ef dbcontext list

使用可能なDbContext型を一覧表示する。

$ dotnet ef dbcontext list

dotnet ef dbcontext scaffold

DbContext のコードとデータベースのエンティティ型を生成する。

# dotnet ef dbcontext scaffold "接続文字列" "プロバイダー(通常はnugetのパッケージ)" -o "エンティティクラスを出力するディレクトリ"
$ dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models

dotnet ef migrations add

新しいマイグレーションファイルを追加する。

$ dotnet ef migrations add [マイグレーション名]

dotnet ef migrations list

使用可能なマイグレーションを表示する。

$ dotnet ef migrations list

dotnet ef migrations remove

最後のマイグレーションを削除して、最新のマイグレーションのために行われたコード変更をロールバックします。

$ dotnet ef migrations remove
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3