日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

core identity mysql_Microsoft.AspNetCore.Identity 使用 mysql 报错处理

發布時間:2023/12/2 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 core identity mysql_Microsoft.AspNetCore.Identity 使用 mysql 报错处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.使用mysql 首先要確定mysql connector 支的版本,正面是鏈接

https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core.html

Table?9.2?Supported versions of Entity Framework Core

Connector/NETEF Core 1.1EF Core 2.0EF Core 2.1

6.10.4

.NET Standard 1.3 or .NET Framework 4.5.2 (and later)

Not supported

Not supported

6.10.5 to 6.10.7

.NET Standard 1.3 or .NET Framework 4.5.2 (and later)

.NET Standard 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported

6.10.8

.NET Standard 1.3 or .NET Framework 4.5.2

.NET Standard 2.0 or .NET Framework 4.6.1 (and later)

Not supported

8.0.11 to 8.0.12

.NET Standard 1.6 or .NET Framework 4.5.2 (and later)

.NET Standard 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported

8.0.13

.NET Standard 1.6 or .NET Framework 4.5.2

Not supported

.NET Standard 2.0 or .NET Framework 4.6.1 (and later)

2.配置數據庫連接字符串

{

"ConnectionStrings": {

"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebMvc-6350BA27-C046-416F-B717-F8342091E6E4;Trusted_Connection=True;MultipleActiveResultSets=true",

"MysqlConnection": "server=localhost;database=mydb;uid=root;pwd=123456;"

},

"Logging": {

"IncludeScopes": false,

"LogLevel": {

"Default": "Warning"

}

}

}

3 修改StartUP

public void ConfigureServices(IServiceCollection services)

{

services.AddDbContext(options =>

options.UseMySQL(Configuration.GetConnectionString("MysqlConnection")));

services.AddIdentity()

.AddEntityFrameworkStores()

.AddDefaultTokenProviders();

// Add application services.

services.AddTransient();

services.AddMvc();

}

4 生成Migration ,數據遷移過程中有一個bug就是原生 clr bool類型為強轉成short類型,如果要程序不報錯需要做一個強制轉換,在使用Add-Migration InitialCreate? 方法對生成的代碼需要加以下注釋

//

using System;

using Microsoft.EntityFrameworkCore;

using Microsoft.EntityFrameworkCore.Infrastructure;

using Microsoft.EntityFrameworkCore.Migrations;

using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

using WebMvc.Data;

namespace WebMvc.Migrations

{

[DbContext(typeof(ApplicationDbContext))]

[Migration("20181210165422_Update")]

partial class Update

{

protected override void BuildTargetModel(ModelBuilder modelBuilder)

{

#pragma warning disable 612, 618

modelBuilder

.HasAnnotation("ProductVersion", "2.2.0-rtm-35687");

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>

{

b.Property("Id")

.ValueGeneratedOnAdd().HasMaxLength(50);

b.Property("ConcurrencyStamp")

.IsConcurrencyToken();

b.Property("Name")

.HasMaxLength(256);

b.Property("NormalizedName")

.HasMaxLength(256);

b.HasKey("Id");

b.HasIndex("NormalizedName")

.IsUnique()

.HasName("RoleNameIndex");

b.ToTable("AspNetRoles");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>

{

b.Property("Id")

.ValueGeneratedOnAdd().HasMaxLength(50);

b.Property("ClaimType");

b.Property("ClaimValue");

b.Property("RoleId")

.IsRequired().HasMaxLength(50);

b.HasKey("Id");

b.HasIndex("RoleId");

b.ToTable("AspNetRoleClaims");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>

{

b.Property("Id")

.ValueGeneratedOnAdd().HasMaxLength(50);

b.Property("ClaimType");

b.Property("ClaimValue");

b.Property("UserId")

.IsRequired();

b.HasKey("Id");

b.HasIndex("UserId");

b.ToTable("AspNetUserClaims");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>

{

b.Property("LoginProvider").HasMaxLength(50);

b.Property("ProviderKey").HasMaxLength(50);

b.Property("ProviderDisplayName");

b.Property("UserId")

.IsRequired();

b.HasKey("LoginProvider", "ProviderKey");

b.HasIndex("UserId");

b.ToTable("AspNetUserLogins");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>

{

b.Property("UserId").HasMaxLength(50);

b.Property("RoleId").HasMaxLength(50);

b.HasKey("UserId", "RoleId");

b.HasIndex("RoleId");

b.ToTable("AspNetUserRoles");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>

{

b.Property("UserId").HasMaxLength(50);

b.Property("LoginProvider").HasMaxLength(50);

b.Property("Name").HasMaxLength(50);

b.Property("Value");

b.HasKey("UserId", "LoginProvider", "Name");

b.ToTable("AspNetUserTokens");

});

modelBuilder.Entity("WebMvc.Models.ApplicationUser", b =>

{

b.Property("Id")

.ValueGeneratedOnAdd();

b.Property("AccessFailedCount");

b.Property("ConcurrencyStamp")

.IsConcurrencyToken();

b.Property("Email")

.HasMaxLength(256);

b.Property("EmailConfirmed")

.HasColumnType("bit");

b.Property("LockoutEnabled")

.HasColumnType("bit");

b.Property("LockoutEnd");

b.Property("NormalizedEmail")

.HasMaxLength(256);

b.Property("NormalizedUserName")

.HasMaxLength(256);

b.Property("PasswordHash");

b.Property("PhoneNumber");

b.Property("PhoneNumberConfirmed")

.HasColumnType("bit");

b.Property("SecurityStamp");

b.Property("TwoFactorEnabled")

.HasColumnType("bit");

b.Property("UserName")

.HasMaxLength(256);

b.HasKey("Id");

b.HasIndex("NormalizedEmail")

.HasName("EmailIndex");

b.HasIndex("NormalizedUserName")

.IsUnique()

.HasName("UserNameIndex");

b.ToTable("AspNetUsers");

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>

{

b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")

.WithMany()

.HasForeignKey("RoleId")

.OnDelete(DeleteBehavior.Cascade);

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>

{

b.HasOne("WebMvc.Models.ApplicationUser")

.WithMany()

.HasForeignKey("UserId")

.OnDelete(DeleteBehavior.Cascade);

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>

{

b.HasOne("WebMvc.Models.ApplicationUser")

.WithMany()

.HasForeignKey("UserId")

.OnDelete(DeleteBehavior.Cascade);

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>

{

b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")

.WithMany()

.HasForeignKey("RoleId")

.OnDelete(DeleteBehavior.Cascade);

b.HasOne("WebMvc.Models.ApplicationUser")

.WithMany()

.HasForeignKey("UserId")

.OnDelete(DeleteBehavior.Cascade);

});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>

{

b.HasOne("WebMvc.Models.ApplicationUser")

.WithMany()

.HasForeignKey("UserId")

.OnDelete(DeleteBehavior.Cascade);

});

#pragma warning restore 612, 618

}

}

}

源碼下載

總結

以上是生活随笔為你收集整理的core identity mysql_Microsoft.AspNetCore.Identity 使用 mysql 报错处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。