记录mysql迁移问题

如果视图使用DbSet,sql server 是支持的,但是mysql必须是用DbQuery,否则视图会报各种类型转换的异常

bool类型 使用tinyint 类型,连接字符串加上 TreatTinyAsBoolean=false ,否则也是各种类型的转换失败,比如

Unable to cast object of type 'System.Boolean' to type 'System.SByte'.

Unable to cast object of type 'System.Byte[]' to type 'System.Boolean'.

//下面代码是统一把bool类型制定为MySQL的tinyint(1)类型,context上下文中写这段代码,连接字符串需要加上TreatTinyAsBoolean=false

var list = modelBuilder.Model.GetEntityTypes().Where(x => !x.IsQueryType).SelectMany(x => x.GetProperties()).Where(x => x.ClrType == typeof(bool) || x.ClrType == typeof(bool?)).Select(x => modelBuilder.Entity(x.DeclaringEntityType.ClrType).Property(x.Name)).ToList();
foreach (var item in list)
{
  item.HasColumnType("tinyint(1)");
}
原文地址:https://www.cnblogs.com/dazen/p/13153760.html