0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Blazor WebAssembly Postgresを使うまで

Last updated at Posted at 2021-09-12

はじめに

この記事はPostgresでBlazorを使えるようにするまでの記事です。

NuGetでインストールが必要なもの

  • Npgsql.EntityFrameworkCore.PostgreSQL
  • Npgsql.EntityFrameworkCore.PostgreSQL.Design

コード側の変更点

  • Server側のStartup.csファイルのUseSqlServerUseNpgsqlに以下を変更
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
Configuration.GetConnectionString("DefaultConnection")));
  • appsettings.json
    DefaultConnectionの部分、接続先をPostgresのDBへ設定

 Data/Migrationsの中のファイルを全て削除

このフォルダにはコマンドAdd-Migration InitialMigrationなどで作成したファイル(DB構成の変更情報)が格納されるが、デフォルトではSQLServerのDBを更新する内容でありPostresにあったものではないため削除をする。

 パッケージマネージャーコンソールでコマンド実行

  • Add-Migration InitialMigrationを実行し、Postgres用のMigrationファイルを生成する。
  • Update-Databaseを実行しMigrationファイルを実行

 動作確認

アカウント作成が出来れば正常にPostgresを使えている。
キャプチャ8.PNG


[Blazor関連のリンク] [Blazor WebAssembly プロジェクト作成(認証あり)](https://qiita.com/pero_88/items/be142d5d0ba92e5c91d0) [Blazor WebAssembly 初期プロジェクト構成の入門](https://qiita.com/pero_88/items/ced1028ad536a43fec1d) [Blazor WebAssembly Postgresを使うまで](https://qiita.com/pero_88/items/23e88a1d2bc3659b9946) [Blazor WebAssembly コードビハインド](https://qiita.com/pero_88/items/be871f4ac63868f048f0) [Blazor WebAssembly InputSelectの使い方](https://qiita.com/pero_88/items/3eddcd1aedf8bbc8441b)
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?