简单插入,返回成功/失败
new DBHelper<DTStudentModel>()
.Insert()
.Execute(new DTStudentModel()
{
StuCode = "01",
StuName = "张三",
StuAge = DateTime.Parse("2012-10-02"),
StuSex = "男"
});
-- 对应 SQL
insert into T_Student(StuCode, StuName, StuAge, StuSex)values(@StuCode, @StuName, @StuAge, @StuSex)
简单插入,返回影响行数
new DBHelper<DTStudentModel>()
.Insert()
.AffectedRows(new DTStudentModel()
{
StuCode = "01",
StuName = "张三",
StuAge = DateTime.Parse("2012-10-02"),
StuSex = "男"
});
-- 对应 SQL
insert into T_Student(StuCode, StuName, StuAge, StuSex)values(@StuCode, @StuName, @StuAge, @StuSex)
简单插入,返回自增编号
new DBHelper<DTStudentModel>()
.Insert()
.Increment(new DTStudentModel()
{
StuCode = "01",
StuName = "张三",
StuAge = DateTime.Parse("2012-10-02"),
StuSex = "男"
});
-- 对应 SQL
insert into T_Student(StuCode, StuName, StuAge, StuSex)values(@StuCode, @StuName, @StuAge, @StuSex);select SCOPE_IDENTITY();
简单插入,排除某些字段
new DBHelper<DTStudentModel>()
.Exclude(p => new { p.StuAge })
.Insert()
.Execute(new DTStudentModel()
{
StuCode = "01",
StuName = "张三",
StuAge = DateTime.Parse("2012-10-02"),
StuSex = "男"
});
-- 对应 SQL
insert into T_Student(StuCode, StuName, StuSex)values(@StuCode, @StuName, @StuSex)
简单插入,按条件判断
new DBHelper<DTStudentModel>()
.Condition(p => p.StuAge, () =>
{
return false;
})
.Insert()
.Execute(new DTStudentModel()
{
StuCode = "01",
StuName = "张三",
StuAge = DateTime.Parse("2012-10-02"),
StuSex = "男"
});
-- 对应 SQL
insert into T_Student(StuCode, StuName, StuSex)values(@StuCode, @StuName, @StuSex)
批量插入,不宜过多,只支持 Exclude 前置函数
int affectedRows = new DBHelper<DTStudentModel>()
.Insert()
.AffectedRows(new List<object>()
{
new { StuCode = "123", StuName = "张三", StuAge = DateTime.Parse("2023-02-12 13:23:32"), StuSex = "男" },
new { StuCode = "456", StuName = "李四", StuAge = DateTime.Parse("2023-11-12 18:11:02"), StuSex = "女" },
new { StuCode = "789", StuName = "王五", StuAge = DateTime.Parse("2021-03-11 05:04:23"), StuSex = "男" },
});
-- 对应 SQL
insert into [T_Student](StuCode,StuName,StuAge,StuSex)values('123','张三','2023/2/12 13:23:32','男'),('456','李四','2023/11/12 18:11:02','女'),('789','王五','2021/3/11 5:04:23','男')