三、编辑 Update set
文档目录
开始使用 初始化查询实例:
LambdaToSql.SqlClient DB = new LambdaToSql.SqlClient();
更新单个实体对象,必须有主键Guid
var entity = DB.QueryTable<EntityModel.System_UserInfo>(ex => ex.Guid == Guid.Parse("7ced7595-32ab-471a-a92d-1698abda04b0")).FirstOrDefault(); entity.PassWord = "234"; var i = DB.UpdateTble(entity).ExecuteNonQuery();
var guid = Guid.Parse("7ced7595-32ab-471a-a92d-1698abda04b0"); var i = DB.UpdateTble(new EntityModel.System_UserInfo() { Guid = guid, PassWord = "123456" }).ExecuteNonQuery();
更新特定字段
var entity = DB.QueryTable<EntityModel.System_UserInfo>(ex => ex.Guid == Guid.Parse("7ced7595-32ab-471a-a92d-1698abda04b0")).FirstOrDefault(); entity.PassWord = "234"; entity.IdCard = "210181"; var i = DB.UpdateTble(entity).UpdateColumns(ex => new { ex.PassWord, ex.IdCard }).ExecuteNonQuery();
忽略特定字段,其他字段都更新
var entity = DB.QueryTable<EntityModel.System_UserInfo>(ex => ex.Guid == Guid.Parse("7ced7595-32ab-471a-a92d-1698abda04b0")).FirstOrDefault(); entity.PassWord = "234"; entity.IdCard = "210181"; var i = DB.UpdateTble(entity).UpdateColumns(ex => new { ex.ImgUrl, ex.LoginName }).ExecuteNonQuery();
条件批量更新
var i = DB.UpdateTble(new EntityModel.System_UserInfo() { PassWord = "123456", IdCard = "210181" }).Where(ex => ex.PassWord == "1").ExecuteNonQuery();
说明
NULL列不做更新处理
暂时只支持Guid类型单主键,后续会增加int自增主键