mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Add Enable Update Version Validation
This commit is contained in:
55
Src/Asp.Net/SqlServerTest/Demos/F_VersionValidation.cs
Normal file
55
Src/Asp.Net/SqlServerTest/Demos/F_VersionValidation.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user