常见问题
  出现错误提示: Specified key was too long;max key length is 767 bytes
  1)查看实体的字符串类型属性是否设置了长度
  2)MyContext 类中是否声明为生成为mysql 数据类型的 [DbConfigurationType(typeof(MySqlEFConfiguration))]
  出现错误提示:    Model compatibility cannot be checked because the database does not contain model metadata
  删除已生成的数据库后重新运行程序
  出现错误提示:序列不包含任何匹配元素
  检查一下:
  例如:1.
public class Employee
{
[Key]
public int EmployeeId { get; set; }
public string Name { get; set; }
[ForeignKey("ManagerId")]
public Employee Manager { get; set; }
public int ManagerId { get; set; }
}
[ForeignKey("ManagerId")]
public Employee Manager { get; set; }
public int ManagerId { get; set; }
这个外键设置。
  2.
[Column(TypeName="VARCHAR(254)")]
public string ColumnName { get; set; }
这样的定义,改成:
[MaxLength(254)] [Column(TypeName="VARCHAR")]
public string ColumnName { get; set; }
  3.(以下代码未测试,因为我不是这样用的,在下篇文章中将进行测试)
modelBuilder.Entity<Category>()
.HasKey(c => c.IdCategory )
.HasOptional(p => p.Children)
.WithMany()
.HasForeignKey(c => c.ChildrenId);
改成:
modelBuilder.Entity<Category>()
.HasKey(c => c.IdCategory )
.HasMany(p => p.Children)
.WithOptional()
.HasForeignKey(c => c.ChildrenId);
.WithMany()换成.WithOptional()