Andrew Kilburn Andrew Kilburn - 3 months ago 18
MySQL Question

How to specify a table type using EF6 Fluent API for MySQL?

So I am using EF6's Fluent API to specify entity properties in my code first application. However I would like to specify a table type for one of my entities, is it possible to do this via the api?


public class ApplicationUser : IdentityUser
public string CreatedBy { get; set; }
public DateTime Active { get; set; }
public DateTime RememberMeTimeOut { get; set; }
public int CentralPermissionUserID { get; set; }
public virtual ICollection<UserLogs> UserLogs { get; set; }

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;

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public ApplicationDbContext()
: base("DBContext", throwIfV1Schema: false)

public DbSet<UserLogs> UserLogs { get; set; }
public DbSet<Supplier> Supplier { get; set; }
public DbSet<SupplierArchive> SupplierArchive { get; set; }
public DbSet<MenuStatsSummary> MenuStatsSummary { get; set; }
public DbSet<Pot> Pots { get; set; }
public DbSet<PotDupeStandards> PotDupeStandards { get; set; }
public DbSet<DupeStandards> DupeStandards { get; set; }
public DbSet<DupeStandardMapping> DupeStandardMapping { get; set; }
public DbSet<DupeData> DupeData { get; set; }

public static ApplicationDbContext Create()
return new ApplicationDbContext();
protected override void OnModelCreating(DbModelBuilder modelBuilder)

#region Application User
modelBuilder.Entity<ApplicationUser>().Property(u => u.UserName).HasMaxLength(255);

modelBuilder.Entity<ApplicationUser>().Property(u => u.Email).HasMaxLength(255);

modelBuilder.Entity<ApplicationUser>().Property(u => u.CreatedBy).HasMaxLength(50).IsRequired();

modelBuilder.Entity<ApplicationUser>().Property(u => u.CentralPermissionUserID).IsRequired();

.HasMany(u => u.UserLogs)
.WithRequired(u => u.User)
.HasForeignKey(u => u.UserID)

.Property(u => u.Email)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UQ_Email") { IsUnique = true }));

.Property(u => u.UserName)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UQ_UserName") { IsUnique = true }));

So lets say I wanted to set the
table to use the
table engine, how can I do this?


To do this you need to create a migration and then write your own Sql commands in the Up method like so:

Sql("DROP TABLE Badger");