当前位置: 首页>>代码示例>>C#>>正文


C# TrackerContext.BeginTransaction方法代码示例

本文整理汇总了C#中Tracker.SqlServer.CodeFirst.TrackerContext.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# TrackerContext.BeginTransaction方法的具体用法?C# TrackerContext.BeginTransaction怎么用?C# TrackerContext.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tracker.SqlServer.CodeFirst.TrackerContext的用法示例。


在下文中一共展示了TrackerContext.BeginTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MaintainAcrossSaves

        public void MaintainAcrossSaves()
        {
            var auditConfiguration = AuditConfiguration.Default;

            auditConfiguration.IncludeRelationships = true;
            auditConfiguration.LoadRelationships = true;
            auditConfiguration.DefaultAuditable = true;
            auditConfiguration.MaintainAcrossSaves = true;

            // customize the audit for Task entity
            //auditConfiguration.IsAuditable<Task>()
            //  .NotAudited(t => t.TaskExtended)
            //  .FormatWith(t => t.Status, v => FormatStatus(v));

            // set name as the display member when status is a foreign key
            auditConfiguration.IsAuditable<Status>()
              .DisplayMember(t => t.Name);

            var db = new TrackerContext();
            var tran = db.BeginTransaction();
            var audit = db.BeginAudit();

            var user = db.Users.Find(1);
            user.Comment = "Testing: " + DateTime.Now.Ticks;

            var task = new Task()
            {
                AssignedId = 1,
                StatusId = 1,
                PriorityId = 2,
                Summary = "Summary: " + DateTime.Now.Ticks,
                CreatedId = 1,
                CreatedDate = DateTime.Now,
                ModifiedDate = DateTime.Now
            };
            db.Tasks.Add(task);

            db.SaveChanges();

            Assert.IsNotNull(audit.LastLog);
            Assert.AreEqual(2, audit.LastLog.Entities.Count);


            var task2 = db.Tasks.Find(1);
            task2.PriorityId = 2;
            task2.StatusId = 2;
            task2.Summary = "Summary: " + DateTime.Now.Ticks;

            db.SaveChanges();

            Assert.IsNotNull(audit.LastLog);
            Assert.AreEqual(3, audit.LastLog.Entities.Count);

            var log = audit.LastLog;
            Assert.IsNotNull(log);

            string xml = log.ToXml();
            Assert.IsNotNull(xml);

            foreach (var property in log.Entities.SelectMany(e => e.Properties))
            {
                Assert.AreNotEqual(property.Current, "{error}");
                Assert.AreNotEqual(property.Original, "{error}");
            }

            //undo work
            tran.Rollback();
        }
开发者ID:reconcilor,项目名称:EntityFramework.Extended,代码行数:68,代码来源:AuditTest.cs


注:本文中的Tracker.SqlServer.CodeFirst.TrackerContext.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。