动态更新实体报错(自己生成类和使用dynamic都不行) 返回

SqlSugar 老数据
3 2107
该叫什么 道叙 发布于2019/7/18
悬赏:0 飞吻


执行报错:ExecuteNonQuery: CommandText 属性尚未初始化,但是调试看entity已经有值了,请教这是为什么,使用了ToSql()看了的确是空的?


代码如下:评论也贴了一份方便看


image.png

热忱回答3

  • 道叙 道叙 VIP0
    2019/7/18

    try

                {

                    var _UAS_Customer_DBContext = new SqlSugarClient(new ConnectionConfig()

                    {

                        ConnectionString = "",

                        DbType = SqlSugar.DbType.SqlServer,

                        IsAutoCloseConnection = true,

                        InitKeyType = InitKeyType.SystemTable

                    });


                    string str = "{'Account':'zhangsan','SaleRegion':'华东2','saascode':'xywy'}";



                    var t = BuildType($"UserCustomerProperty_xywy");

                    var list = new List<CustPropertyInfo>();

                    list.Add(new CustPropertyInfo() { PropertyName = "Account", Type = typeof(string).ToString() });

                    list.Add(new CustPropertyInfo() { PropertyName = "SaleRegion", Type = typeof(string).ToString() });

                    t = AddPropertyToType(t, list);


                    var obj = JsonConvert.DeserializeObject<dynamic>(str);


                    var entity = CreateInstance(t);


                    SetPropertyValue(entity, "Account", "zhangsan");


                    SetPropertyValue(entity, "SaleRegion", "华东2");


                    //ExecuteNonQuery: CommandText 属性尚未初始化

                    //但是entity已经有值了

                    var ssss = _UAS_Customer_DBContext.Updateable(entity).WhereColumns("Account").ExecuteCommand();

                }

                catch (Exception ex)

                {



                }



    0 回复
  • 需要强类型

    0 回复
  • 道叙 道叙 VIP0
    2020/11/16

    @fate stay night: 明白,已经调整了,项目中的动态类型比较多

    0 回复