Instantly share code, notes, and snippets.

@pysco68 /1-ApplicationUser.cs Secret
Last active Aug 29, 2015

Embed
What would you like to do?
ApplicationUser class
namespace Application.Model
{
using Microsoft.AspNet.Identity.EntityFramework;
public class ApplicationUser : IdentityUser
{
// add whatever properties you want your user to have here
}
}
namespace Application.Model
{
using Microsoft.AspNet.Identity.EntityFramework;
using MySql.Data.Entity;
using System.Data.Entity;
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ApplicationContext : IdentityDbContext<ApplicationUser>
{
/// <summary>
/// To use this constructor you have to have a connection string
/// name "MyConnection" in your configuration
/// </summary>
public ApplicationContext() : this("MyConnection") { }
/// <summary>
/// Construct a db context
/// </summary>
/// <param name="connStringName">Connection to use for the database</param>
public ApplicationContext(string connStringName) : base(connStringName) { }
/// <summary>
/// Some database fixup / model constraints
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
#region Fix asp.net identity 2.0 tables under MySQL
// Explanations: primary keys can easily get too long for MySQL's
// (InnoDB's) stupid 767 bytes limit.
// With the two following lines we rewrite the generation to keep
// those columns "short" enough
modelBuilder.Entity<IdentityRole>()
.Property(c => c.Name)
.HasMaxLength(128)
.IsRequired();
// We have to declare the table name here, otherwise IdentityUser
// will be created
modelBuilder.Entity<ApplicationUser>()
.ToTable("AspNetUsers")
.Property(c => c.UserName)
.HasMaxLength(128)
.IsRequired();
#endregion
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment