使用函数,函数可以嵌套
new DBHelper<DTStudentModel>()
.Update(p => new
{
StuCode = DBMethod.Lower(p.StuCode),
StuName = DBMethod.Trim(p.StuName)
})
.Where(p => p.IdentityID == p.IdentityID);
.Execute(new DTStudentModel()
{
IdentityID = 1
});
-- 对应 SQL
update T_Student set T_Student.[StuCode]=Lower([T_Student].[StuCode]),T_Student.[StuName]=RTRIM(LTRIM([T_Student].[StuName])) where ([T_Student].[IdentityID] = @IdentityID)
使用子查询
new DBHelper<DTStudentModel>()
.Update(p => new
{
p.StuCode,
})
.UpdateSub<DTStudentModel>(p => p.StuSex, new DBHelper<DTStudentModel>().Select(p => new { p.StuSex }).Where(p => p.StuCode == "01"))
.Where(p => p.IdentityID == p.IdentityID);
.AffectedRows(new DTStudentModel()
{
IdentityID = 1,
StuCode = "01",
});
-- 对应 SQL
update T_Student set [T_Student].[StuSex]=(select [T_Student].[StuSex] as [StuSex] from T_Student where ([T_Student].[StuCode] = '01')),T_Student.[StuCode]=@StuCode where ([T_Student].[IdentityID] = @IdentityID)