插入或更新-分表扩展使用-分表的统计插入和更新 返回

SqlSugar 处理完成
2 231
   
    
    public long AddListZlDetailsSplitTable(List<ZlDetails> model)
    {
        var db = DbScoped.SugarScope;
        foreach (var m in model)
        {
            if (m.DetailID == 0) // 若你的“未赋值”判断不同,请按实际调整
                m.DetailID = SnowFlakeSingle.Instance.NextId();
        }
        var result = db.Storageable(model).WhereColumns(x => new { x.ProjectCode, x.CollectTime }).SplitTable().ExecuteCommand();
        return result;
    }

上面是一个分表成功执行的插入或更新+mysql5

image.png

image.png

再改造方法,想和单表一样能分表统计插入更新,分表执行到ToStorage报错

image.png

--错误信息

System.ArgumentNullException: Value cannot be null. (Parameter 'source')

   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)

   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)

   at SqlSugar.Storageable`1.GetPkProperties(IEnumerable`1 pkInfos)

   at SqlSugar.Storageable`1.ToStorage()

   at SqlSugar.Storageable`1.ToStorage()


单表成功,分表卡再这一步,如果前面加入.SplitTable()会造成ToStorage未定义,网上查询无果,这里是不支持吗

    var storage = db.Storageable(model)

        .WhereColumns(x => new { x.ProjectCode, x.CollectTime })

         .ToStorage();


热忱回答2

  • fate sta fate sta VIP0
    1个月前

    看文档:分表的写法。

    只能按文档定法,不支持    .ToStorage();

    0 回复
  • fate sta fate sta VIP0
    1个月前

     var result = db.Storageable(model).WhereColumns(x => new { x.ProjectCode, x.CollectTime }).SplitTable().ExecuteCommand();

    只支持这种

    0 回复