希望可以加入记录版本控制的功能 返回
C#论坛
老数据
7
2498
悬赏:5 飞吻
希望可以在数据库表里增加一个版本控制字段, 实体如果用了类似@Version就启用版本控制功能
1) 添加时,字段值为0
2) 当有更新的时候,字段值自动加1
3) 如果要更新的记录版本小于数据库记录的版本,提示错误
热忱回答(7)
-
hz_bule VIP0
2018/10/10支持增加此功能!
0 回复 -
fate stay night VIP0
2018/10/105.X 已经有这功能了,还在开发中。
0 回复 -
fate stay night VIP0
2018/10/13using 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() { TimestampDome(); DateTimeDome(); } private static void TimestampDome() { var db = GetInstance(); try { var data = new StudentVersion() { Id = db.Queryable<Student>().Select(it => it.Id).First(), CreateTime = DateTime.Now, Name = "", }; db.Updateable(data).IgnoreColumns(it => new { it.Timestamp }).ExecuteCommand(); var time = db.Queryable<StudentVersion>().Where(it => it.Id == data.Id).Select(it => it.Timestamp).Single(); data.Timestamp = time; //is ok db.Updateable(data).IsEnableUpdateVersionValidation().IgnoreColumns(it => new { it.Timestamp }).ExecuteCommand(); //updated Timestamp change //is error db.Updateable(data).IsEnableUpdateVersionValidation().IgnoreColumns(it => new { it.Timestamp }).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 { } } } 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 { public int Id { get; set; } public string Name { get; set; } public DateTime CreateTime { get; set; } [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; } } } }0 回复 -
fate stay night VIP0
2018/10/13已经更新到GITHUB
0 回复 -
Alex VIP0
2018/10/15太完美了,谢谢
0 回复 -
Alex VIP0
2018/10/15@fate stay night:太完美了,谢谢
0 回复 -
Alex VIP0
2018/10/15@fate stay night:想问一下,应用了IsEnableUpdateVersionValidation的记录,同一个事务内是否可以更新多次?
0 回复