3
3

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 5 years have passed since last update.

Blazor(.NET CORE)でMySQLを使用する

Posted at

環境

VisualStudio2019
.NET CORE 3.1
MySQL8.0

手順

Blazorアプリの作成

blazor-mysql1.png

blazor-mysql2.png

今回は認証を個別のユーザーアカウントにしておきます。
blazor-mysql3.png

SQLServer用のMigrationファイルを削除します。

blazor-mysql4.png

appsettings.jsonをMySQL用に書き換え

appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;user id=xxxx;password=xxxx;database=xxxx"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

NuGetパッケージの管理から「Pomelo.EntityFrameworkCore.MySql」をインストールします。

blazor-mysql6.png

###「"UseSqlServer"の定義が含まれておらず...」のエラーが発生するので、UseSqlServerを「UseMySql」に変更
[変更前]
blazor-mysql9.png

[変更後]
blazor-mysql10.png

パッケージマネージャーコンソールで下記コマンドを入力

add-migration 'identity'

blazor-mysql11.png

続けて下記コマンドを入力

Update-Database

アプリを起動してユーザー登録を行う

データが登録されていれば完了

blazor-mysql13.png

参考記事

3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?