|
|
@ -57,25 +57,25 @@ namespace OrmTest.Demo |
|
|
|
//Update Student set Name='jack' Where Id=1
|
|
|
|
|
|
|
|
//Column is null no update
|
|
|
|
db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand(); |
|
|
|
db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); |
|
|
|
|
|
|
|
//sql
|
|
|
|
db.Updateable(updateObj).Where("id=@x",new { x="1"}).ExecuteCommand(); |
|
|
|
db.Updateable(updateObj).Where("id","=",1).ExecuteCommand(); |
|
|
|
db.Updateable(updateObj).Where("id=@x", new { x = "1" }).ExecuteCommand(); |
|
|
|
db.Updateable(updateObj).Where("id", "=", 1).ExecuteCommand(); |
|
|
|
var t12 = db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommandAsync(); |
|
|
|
t12.Wait(); |
|
|
|
|
|
|
|
//update one columns
|
|
|
|
var count = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId).Where(it => it.Id == it.Id+1).ExecuteCommand(); |
|
|
|
var count = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId).Where(it => it.Id == it.Id + 1).ExecuteCommand(); |
|
|
|
|
|
|
|
var count1 = db.Updateable<Student>() |
|
|
|
.UpdateColumnsIF(false,it => it.SchoolId == it.SchoolId)//ignore
|
|
|
|
.UpdateColumnsIF(false, it => it.SchoolId == it.SchoolId)//ignore
|
|
|
|
.UpdateColumnsIF(true, it => it.SchoolId == 2).//ok
|
|
|
|
Where(it => it.Id == it.Id + 1).ExecuteCommand(); |
|
|
|
|
|
|
|
|
|
|
|
//update one columns
|
|
|
|
var count2 = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId+1).Where(it => it.Id == it.Id + 1).ExecuteCommand(); |
|
|
|
var count2 = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId + 1).Where(it => it.Id == it.Id + 1).ExecuteCommand(); |
|
|
|
|
|
|
|
var dt = new Dictionary<string, object>(); |
|
|
|
dt.Add("id", 1); |
|
|
@ -83,7 +83,7 @@ namespace OrmTest.Demo |
|
|
|
dt.Add("createTime", DateTime.Now); |
|
|
|
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").With(SqlWith.UpdLock).ExecuteCommand(); |
|
|
|
|
|
|
|
db.Updateable(new Student() { Id = 1 }).UpdateColumns(new string[] { "name" }).Where(it=>it.Name=="1").ExecuteCommand(); |
|
|
|
db.Updateable(new Student() { Id = 1 }).UpdateColumns(new string[] { "name" }).Where(it => it.Name == "1").ExecuteCommand(); |
|
|
|
|
|
|
|
var dt2 = new Dictionary<string, object>(); |
|
|
|
dt2.Add("id", 2); |
|
|
@ -99,35 +99,40 @@ namespace OrmTest.Demo |
|
|
|
{ |
|
|
|
SchoolId = SqlFunc.IIF(p.Id == 1, 2, 3) |
|
|
|
}).Where(p => p.Id == 10000).ExecuteCommand(); |
|
|
|
var t21= db.Updateable<Student>().UpdateColumns(p => new Student() |
|
|
|
var t21 = db.Updateable<Student>().UpdateColumns(p => new Student() |
|
|
|
{ |
|
|
|
SchoolId = SqlFunc.IF(p.Id==1).Return(1).End(p.Id) |
|
|
|
SchoolId = SqlFunc.IF(p.Id == 1).Return(1).End(p.Id) |
|
|
|
}).Where(p => p.Id == 10000).ExecuteCommand(); |
|
|
|
|
|
|
|
|
|
|
|
var t22= db.Updateable<Student>().UpdateColumns(p => new Student() |
|
|
|
var t22 = db.Updateable<Student>().UpdateColumns(p => new Student() |
|
|
|
{ |
|
|
|
SchoolId = SqlFunc.Subqueryable<Student>().Where(s=>s.SchoolId==p.Id).Select(s=>s.Id) |
|
|
|
SchoolId = SqlFunc.Subqueryable<Student>().Where(s => s.SchoolId == p.Id).Select(s => s.Id) |
|
|
|
}).Where(p => p.Id == 10000).ExecuteCommand(); |
|
|
|
|
|
|
|
|
|
|
|
var t23= db.Updateable<Student>(new Student() { }) |
|
|
|
var t23 = db.Updateable<Student>(new Student() { }) |
|
|
|
.Where(p => p.SchoolId == SqlFunc.Subqueryable<Student>().Where(s => s.SchoolId == p.Id).Select(s => s.Id)).ExecuteCommand(); |
|
|
|
|
|
|
|
var t24 = db.Updateable(new Student() { }).WhereColumns(it=>it.CreateTime).ExecuteCommand(); |
|
|
|
var t24 = db.Updateable(new Student() { }).WhereColumns(it => it.CreateTime).ExecuteCommand(); |
|
|
|
|
|
|
|
var t25 = db.Updateable(new Student() { }).UpdateColumns(it=> new { it.Name,it.CreateTime}).WhereColumns(it => it.CreateTime).ExecuteCommand(); |
|
|
|
var t25 = db.Updateable(new Student() { }).UpdateColumns(it => new { it.Name, it.CreateTime }).WhereColumns(it => it.CreateTime).ExecuteCommand(); |
|
|
|
|
|
|
|
var t26 = db.Updateable(new List<Student>() { new Student() { }, new Student() { } }).UpdateColumns(it => new { it.Name, it.CreateTime }).WhereColumns(it => it.CreateTime).ExecuteCommand(); |
|
|
|
|
|
|
|
|
|
|
|
db.Updateable<Student>().UpdateColumns(it => new Student { SchoolId = GeneratePassword(2, 1), Name =SqlFunc.ToString(it.Name), CreateTime = DateTime.Now.AddDays(1) }).Where(it => it.Id == 1).ExecuteCommand(); |
|
|
|
db.Updateable<Student>().UpdateColumns(it => new Student { SchoolId = GeneratePassword(2, 1), Name = SqlFunc.ToString(it.Name), CreateTime = DateTime.Now.AddDays(1) }).Where(it => it.Id == 1).ExecuteCommand(); |
|
|
|
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } }) |
|
|
|
.UpdateColumns(it => new { it.Name, it.Id, it.SchoolId }) |
|
|
|
.WhereColumns(it => it.Name) |
|
|
|
.Where(it => it.Id == 1) |
|
|
|
.ExecuteCommand(); |
|
|
|
} |
|
|
|
|
|
|
|
private static int GeneratePassword(int v1, int v2) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|