zoukankan      html  css  js  c++  java
  • 记录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)");
    }
  • 相关阅读:
    销售类
    语法
    编辑技巧 word
    assert
    游戏摘录
    游戏类链接 财富导图
    读书笔记之C# delegate
    c# socket传输struct类型
    关于wcf中一些重要词语解释
    asp.net CROSS-PAGE POSTING
  • 原文地址:https://www.cnblogs.com/dazen/p/13153760.html
Copyright © 2011-2022 走看看