Add Enable Update Version Validation

This commit is contained in:
sunkaixuan
2018-10-13 03:31:18 +08:00
parent 38b107895a
commit 3a6c54d9a6
10 changed files with 175 additions and 20 deletions

View File

@@ -0,0 +1,55 @@
using OrmTest.Demo;
using OrmTest.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class VersionValidation : DemoBase
{
public static void Init()
{
var db = GetInstance();
try
{
for (int i = 0; i < 10; i++)
{
var data = new StudentVersion()
{
Id = db.Queryable<Student>().Select(it => it.Id).First(),
CreateTime = DateTime.Now,
Name = ""
};
db.Updateable(data).AS("student").ExecuteCommand();
var time = db.Queryable<Student>().Where(it=>it.Id==data.Id).Select(it => it.CreateTime).Single();
data.CreateTime = time.Value;
db.Updateable(data).AS("student").ExecuteCommand();
data.CreateTime = time.Value.AddMilliseconds(-1);
db.Updateable(data).AS("student").ExecuteCommand();
}
}
catch (Exception ex)
{
if (ex is SqlSugar.VersionExceptions)
{
Console.Write(ex.Message);
}
else {
}
}
}
public class StudentVersion
{
public int Id { get; set; }
public string Name { get; set; }
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)]
public DateTime CreateTime { get; set; }
}
}
}