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


C# TrackerContext.SaveChanges方法代码示例

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


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

示例1: TestCacheStrategy2

        public void TestCacheStrategy2()
        {
            using (var db = new TrackerContext())
            {
                var role1 = CreateRole("Joe 1");
                var role2 = CreateRole("Joe 2");
                var role3 = CreateRole("Bob 3");
                db.Roles.Add(role1);
                db.Roles.Add(role2);
                db.Roles.Add(role3);

                db.SaveChanges();

                db.Roles.Delete(o => o.Name.StartsWith("J"), CacheStrategy.None);

                db.SaveChanges();

                db.Roles.Local.Where(o => o.Id == role1.Id).Should().NotBeEmpty();
                db.Roles.Local.Where(o => o.Id == role2.Id).Should().NotBeEmpty();
                db.Roles.Local.Where(o => o.Id == role3.Id).Should().NotBeEmpty();

                db.Roles.Where(o => o.Name.StartsWith("J")).Should().BeEmpty();
                db.Roles.Where(o => o.Id == role3.Id).Should().NotBeEmpty();
            }
        }
开发者ID:fpellet,项目名称:EntityFramework.Extended,代码行数:25,代码来源:DeleteTest.cs

示例2: TestCacheStrategy2

        public void TestCacheStrategy2()
        {
            using (var db = new TrackerContext())
            {
                var role1 = CreateRole("Joe 1");
                var role2 = CreateRole("Joe 2");
                var role3 = CreateRole("Bob 3");
                db.Roles.Add(role1);
                db.Roles.Add(role2);
                db.Roles.Add(role3);

                db.SaveChanges();

                db.Roles.Update(o => o.Name.StartsWith("J"), o => new Role { Description = "Updated joe" }, CacheStrategy.None);

                db.SaveChanges();

                db.Roles.Local.Where(o => o.Id == role1.Id).Should().NotBeEmpty();
                db.Roles.Local.Where(o => o.Id == role2.Id).Should().NotBeEmpty();
                db.Roles.Local.Where(o => o.Id == role3.Id).Should().NotBeEmpty();

                db.Roles.Where(o => o.Name.StartsWith("J") && o.Description != "Updated joe").Should().BeEmpty();
                db.Roles.Where(o => o.Id == role3.Id && o.Description == role3.Name).Should().NotBeEmpty();
            }
        }
开发者ID:fpellet,项目名称:EntityFramework.Extended,代码行数:25,代码来源:UpdateTest.cs

示例3: CreateLog3

        public void CreateLog3()
        {
            AuditConfiguration.Default.IncludeRelationships = true;
            AuditConfiguration.Default.LoadRelationships = true;

            AuditConfiguration.Default.IsAuditable<Task>();
            AuditConfiguration.Default.IsAuditable<User>();

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

            var user = new User();
            user.EmailAddress = string.Format("email.{0}@test.com", DateTime.Now.Ticks);
            user.CreatedDate = DateTime.Now;
            user.ModifiedDate = DateTime.Now;
            user.PasswordHash = DateTime.Now.Ticks.ToString();
            user.PasswordSalt = "abcde";
            user.IsApproved = false;
            user.LastActivityDate = DateTime.Now;

            db.Users.Add(user);

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

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

            db.SaveChanges();

            log.Refresh();

            string afterXml = log.ToXml();
            Assert.IsNotNull(afterXml);
        }
开发者ID:jwaala,项目名称:EntityFramework.Extended,代码行数:35,代码来源:AuditTest.cs

示例4: 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

示例5: Update

        public void Update()
        {
            AuditConfiguration.Default.IncludeRelationships = true;
            AuditConfiguration.Default.LoadRelationships = true;

            AuditConfiguration.Default.IsAuditable<Task>();
            AuditConfiguration.Default.IsAuditable<User>().NotAudited(p => p.Avatar);

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

            var user = new User();
            user.EmailAddress = string.Format("email.{0}@test.com", DateTime.Now.Ticks);
            user.CreatedDate = DateTime.Now;
            user.ModifiedDate = DateTime.Now;
            user.PasswordHash = DateTime.Now.Ticks.ToString();
            user.PasswordSalt = "abcde";
            user.IsApproved = false;
            user.LastActivityDate = DateTime.Now;

            db.Users.Add(user);

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

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

            db.SaveChanges();

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

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

            var lastLog = audit.LastLog;
            var lastXml = lastLog.Refresh().ToXml();

            Assert.IsNotNull(lastXml);
            Console.WriteLine(lastXml);

            user.EmailAddress = string.Format("update.{0}@test.com", DateTime.Now.Ticks);

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

            db.SaveChanges();

            var updateXml = updateLog.ToXml();
            Assert.IsNotNull(updateXml);
            Console.WriteLine(updateXml);
        }
开发者ID:reconcilor,项目名称:EntityFramework.Extended,代码行数:62,代码来源:AuditTest.cs

示例6: LogWithNullableRelationWithoutValueAndAllreadyLoadedRelation

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

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

            auditConfiguration.IsAuditable<Task>();
            auditConfiguration.IsAuditable<Priority>().DisplayMember(t => t.Name);

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

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

            var entries = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added);
            var relation = entries.First().RelationshipManager.GetRelatedReference<Priority>("Tracker.SqlServer.CodeFirst.Task_Priority", "Task_Priority_Target");
            relation.Load();

            db.SaveChanges();

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

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

示例7: LogWithNullableRelations

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

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

            auditConfiguration.IsAuditable<Task>();
            auditConfiguration.IsAuditable<Priority>().DisplayMember(t => t.Name);

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

            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();

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

            task.PriorityId = null;
            db.SaveChanges();

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

            task.PriorityId = 1;
            db.SaveChanges();

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

            task.PriorityId = 2;
            db.SaveChanges();

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

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


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