mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Demo
This commit is contained in:
parent
22fa8e501e
commit
35d024d68c
@ -10,6 +10,12 @@ namespace OrmTest.Demo
|
||||
public class VersionValidation : DemoBase
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
TimestampDome();
|
||||
DateTimeDome();
|
||||
}
|
||||
|
||||
private static void TimestampDome()
|
||||
{
|
||||
var db = GetInstance();
|
||||
try
|
||||
@ -49,6 +55,48 @@ namespace OrmTest.Demo
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void DateTimeDome()
|
||||
{
|
||||
var db = GetInstance();
|
||||
try
|
||||
{
|
||||
|
||||
var data = new StudentVersion2()
|
||||
{
|
||||
Id = db.Queryable<Student>().Select(it => it.Id).First(),
|
||||
CreateTime = DateTime.Now,
|
||||
Name = "",
|
||||
};
|
||||
db.Updateable(data).ExecuteCommand();
|
||||
|
||||
var time = db.Queryable<StudentVersion2>().Where(it => it.Id == data.Id).Select(it => it.CreateTime).Single();
|
||||
|
||||
data.CreateTime = time;
|
||||
|
||||
//is ok
|
||||
db.Updateable(data).IsEnableUpdateVersionValidation().ExecuteCommand();
|
||||
|
||||
|
||||
data.CreateTime = time.AddMilliseconds(-1);
|
||||
//is error
|
||||
db.Updateable(data).IsEnableUpdateVersionValidation().ExecuteCommand();
|
||||
|
||||
//IsEnableUpdateVersionValidation Types of support int or long or byte[](Timestamp) or Datetime
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is SqlSugar.VersionExceptions)
|
||||
{
|
||||
Console.Write(ex.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SqlSugar.SugarTable("Student")]
|
||||
public class StudentVersion
|
||||
{
|
||||
@ -58,5 +106,14 @@ namespace OrmTest.Demo
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true,IsOnlyIgnoreInsert=true)]
|
||||
public byte[] Timestamp { get; set; }
|
||||
}
|
||||
|
||||
[SqlSugar.SugarTable("Student")]
|
||||
public class StudentVersion2
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true, IsOnlyIgnoreInsert = true)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,40 @@ namespace OrmTest
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// /***Unit Test***/
|
||||
new Select(1).Init();
|
||||
new Field(1).Init();
|
||||
new Where(1).Init();
|
||||
new Method(1).Init();
|
||||
new JoinQuery(1).Init();
|
||||
new SingleQuery(1).Init();
|
||||
new SelectQuery(1).Init();
|
||||
new AutoClose(1).Init();
|
||||
new Insert(1).Init();
|
||||
new Delete(1).Init();
|
||||
new Update(1).Init();
|
||||
new Mapping(1).Init();
|
||||
new DataTest(1).Init();
|
||||
new EnumTest(1).Init();
|
||||
/***Performance Test***/
|
||||
new SqlSugarPerformance(100).Select();
|
||||
|
||||
Demo.VersionValidation.Init();
|
||||
/***Demo***/
|
||||
Demo.Query.Init();
|
||||
Demo.Insert.Init();
|
||||
Demo.Delete.Init();
|
||||
Demo.Update.Init();
|
||||
Demo.DbFirst.Init();
|
||||
Demo.JoinSql.Init();
|
||||
Demo.Filter.Init();
|
||||
Demo.ComplexModel.Init();
|
||||
Demo.CodeFirst.Init();
|
||||
Demo.Aop.Init();
|
||||
Demo.MasterSlave.Init();
|
||||
Demo.SharedConnection.Init();
|
||||
Demo.ExtSqlFun.Init();
|
||||
Demo.QueryableView.Init();
|
||||
Demo.AttributeDemo.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user