I am trying to implement class inheritance in .NET using Entity Framework 4.1 and MySQL as a database, with a code approach. The model below works with SQL Server, but crashes in MySQL with the following error:
Schema specified is not valid. Errors: (11,6) : error 0064: Facet 'MaxLength' must not be specified for type 'mediumtext'.
The model is a classic simple example:
public abstract class Vehicle { public int Id { get; set; } public int Year { get; set; } } public class Car : Vehicle { public string CarProperty { get; set; } } public class Bike : Vehicle { public string BikeProperty { get; set; } } public class Db : DbContext { public DbSet<Vehicle> Vehicles { get; set; } public DbSet<Car> Cars { get; set; } public DbSet<Bike> Bikes { get; set; } }
In SQL Server, only a table named Vehicles with the columns: Id , Year , Model and Discriminator ; no tables for cars or bicycles. In MySQL, the database is not even created (if I delete the "Car" class, it creates - so this is not a permission problem or something like that).
Any help would be appreciated! Thanks.
UPDATE 1: I tried using the Table-Per-Hierarchy approach to relationships, switching to the context below, but it gave me another error: Can't create table 'aimpa.#sql-da8_2c' (errno: 150) .
public class Db : DbContext { public DbSet<Vehicle> Vehicles { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Vehicle>() .Map<Car>(o => o.ToTable("Cars")) .Map<Bike>(o=>o.ToTable("Bikes")); } }
UPDATE 2: I presented this as a bug for the MySQL development team because I don't know what else I can do. It seems that it should work, but it is not. Permanent link http://bugs.mysql.com/63920 .
UPDATE 3: I upgraded to NHibertnate 3.2 to verify this. Everything seems to be working fine. I would rather consider this ORM, but I would rather stay with EF.
UPDATE 4: In the official MySQL forum, I received a response stating that a fix for this error is under consideration. Should be fixed soon.