Skip to content

Instantly share code, notes, and snippets.

@nishanc
Created February 13, 2019 08:44
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 nishanc/0581422cfb2ef4e4ba4de102793de6d8 to your computer and use it in GitHub Desktop.
Save nishanc/0581422cfb2ef4e4ba4de102793de6d8 to your computer and use it in GitHub Desktop.
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.Migrations.History;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using MySql.Data.Entity;
namespace MedicalCenterApplication.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
this.Configuration.ValidateOnSaveEnabled = false;
}
public static ApplicationDbContext Create()
{
DbConfiguration.SetConfiguration(new MySqlEFConfiguration());
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
modelBuilder.Properties().Where(x =>
x.PropertyType.FullName != null &&
(x.PropertyType.FullName.Equals("System.String") &&
!x.GetCustomAttributes(false).OfType<ColumnAttribute>().Any(q => q.TypeName != null &&
q.TypeName.Equals("varchar(max)", StringComparison.InvariantCultureIgnoreCase)))).Configure(c =>
c.HasColumnType("varchar(65000)"));
modelBuilder.Properties().Where(x =>
x.PropertyType.FullName != null &&
(x.PropertyType.FullName.Equals("System.String") &&
!x.GetCustomAttributes(false).OfType<ColumnAttribute>().Any(q => q.TypeName != null &&
q.TypeName.Equals("nvarchar", StringComparison.InvariantCultureIgnoreCase)))).Configure(c =>
c.HasColumnType("varchar"));
}
public DbSet<User> Users { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment