Created
June 10, 2021 15:40
-
-
Save jasonsturges/2264fdc19013243ba55371f2a91d9525 to your computer and use it in GitHub Desktop.
ASP.NET Core with MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Identity; | |
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | |
using Microsoft.EntityFrameworkCore; | |
public class ApplicationDbContext : IdentityDbContext | |
{ | |
// ... | |
protected override void OnModelCreating(ModelBuilder builder) | |
{ | |
base.OnModelCreating(builder); | |
builder.Entity<IdentityRole>(entity => entity.Property(m => m.Id).HasMaxLength(450)); | |
builder.Entity<IdentityRole>(entity => entity.Property(m => m.ConcurrencyStamp).HasColumnType("varchar(256)")); | |
builder.Entity<IdentityUserLogin<string>>(entity => | |
{ | |
entity.Property(m => m.LoginProvider).HasMaxLength(127); | |
entity.Property(m => m.ProviderKey).HasMaxLength(127); | |
}); | |
builder.Entity<IdentityUserRole<string>>(entity => | |
{ | |
entity.Property(m => m.UserId).HasMaxLength(127); | |
entity.Property(m => m.RoleId).HasMaxLength(127); | |
}); | |
builder.Entity<IdentityUserToken<string>>(entity => | |
{ | |
entity.Property(m => m.UserId).HasMaxLength(127); | |
entity.Property(m => m.LoginProvider).HasMaxLength(127); | |
entity.Property(m => m.Name).HasMaxLength(127); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"ConnectionStrings": { | |
"DefaultConnection":"server=localhost;userid=myusername;password=mypassword;database=mydatabase;" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Add framework services. | |
services.AddDbContext<ApplicationDbContext>(options => | |
options.UseMySQL(Configuration.GetConnectionString("DefaultConnection"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment