MyDAL - .UpdateAsync() 之 .SetSegment 根据条件 动态设置 要更新的字段 使用

it2022-05-05  122

索引:

目录索引

一.API 列表

  1.SetSegment 属性,指示 根据条件 动态拼接 要修改的字段

    见如下示例.

二.API 单表-完整 方法 举例

 

1 // update 要赋值的变量 2 var time = DateTime.Now.ToString(); 3 var propertyVal = "{xxx:yyy,mmm:nnn,zzz:aaa}"; 4 5 // 使用 SetSegment 动态 拼接 set field 起点 6 var set = Conn.Updater<BodyFitRecord>().SetSegment; 7 8 // 根据 条件 判断 是否要对字段 CreatedOn 进行 update 9 if (!time.IsNullStr()) 10 { 11 set = set.Set(it => it.CreatedOn, DateTime.Parse(time)); 12 } 13 14 // 根据 条件 判断 是否要对字段 BodyMeasureProperty 进行 update 15 if (!propertyVal.IsNullStr()) 16 { 17 set = set.Set(it => it.BodyMeasureProperty, propertyVal); 18 } 19 20 // 对 SetSegment 设定的字段 进行 update 动作 21 var res1 = await set 22 .Where(it => it.Id == m.Id) 23 .UpdateAsync(); 24 25 Assert.True(res1 == 1);

  以 MySQL 为例,生成 SQL 如下:

1 update `bodyfitrecord` 2 set `CreatedOn_col`=?CreatedOn_col_1, 3 `BodyMeasureProperty`=?BodyMeasureProperty_2 4 where `Id`=?Id_3;

 

 

 

                                         蒙

                                    2019-04-13 23:59 周六

 

转载于:https://www.cnblogs.com/Meng-NET/p/10703669.html

相关资源:各显卡算力对照表!

最新回复(0)