Skip to content

Instantly share code, notes, and snippets.

@jasonsturges
Created June 10, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonsturges/2264fdc19013243ba55371f2a91d9525 to your computer and use it in GitHub Desktop.
Save jasonsturges/2264fdc19013243ba55371f2a91d9525 to your computer and use it in GitHub Desktop.
ASP.NET Core with MySQL
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);
});
}
"ConnectionStrings": {
"DefaultConnection":"server=localhost;userid=myusername;password=mypassword;database=mydatabase;"
},
// 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