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


C# EFRepository.SaveChanges方法代码示例

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


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

示例1: TransactionsWork

        public void TransactionsWork()
        {
            if (ConfigurationManager.AppSettings["Environment"] == "Test")
                Assert.Ignore("Skipped on AppHarbor");

            using (var repo = new EFRepository<TestContext, TestClass>(x => x.Objects))
            {
                repo.RemoveAll();
                repo.SaveChanges();

                using (var scope = new TransactionScope())
                {
                    repo.Insert(mTestObjects.First());
                    repo.SaveChanges();
                    scope.Complete();
                }
            }

            using (var repo = new EFRepository<TestContext, TestClass>(x => x.Objects))
            {
                Assert.IsTrue(repo.Items.Any());
                repo.RemoveAll();
                repo.SaveChanges();
            }

            using (var repo = new EFRepository<TestContext, TestClass>(x => x.Objects))
            {

                try
                {
                    using (var scope = new TransactionScope())
                    {
                        repo.Insert(mTestObjects.First());
                        repo.SaveChanges();

                        throw new Exception();
                    }
                }

                catch (Exception e)
                {
                    Assert.IsFalse(repo.Items.Any());
                }
            }
        }
开发者ID:simran2jain,项目名称:Repository,代码行数:45,代码来源:Tests.cs

示例2: CreateNews_WithIncorrectData_ShouldThrow

        public void CreateNews_WithIncorrectData_ShouldThrow()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = null, Title = null, PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
        }
开发者ID:WS-and-Cloud,项目名称:News-UnitTests,代码行数:12,代码来源:NewsRepositoryCrud.cs

示例3: Delete_ExistingNews_ShouldDeleteTheNew

        public void Delete_ExistingNews_ShouldDeleteTheNew()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content of new", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();
            repo.Delete(newsInDb[0]);
            repo.SaveChanges();

            // Assert
            Assert.AreEqual(0, repo.All().ToList().Count());
        }
开发者ID:WS-and-Cloud,项目名称:News-UnitTests,代码行数:18,代码来源:NewsRepositoryCrud.cs

示例4: CreateNews_WithCorrectData_ShouldCreateNewsSuccessfully

        public void CreateNews_WithCorrectData_ShouldCreateNewsSuccessfully()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content 1", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();

            // Assert
            Assert.AreEqual(1, newsInDb.Count());
            Assert.AreEqual(new1.Title, newsInDb[0].Title);
            Assert.AreEqual(new1.Content, newsInDb[0].Content);
            Assert.AreEqual(new1.PublishedAt.ToString(), newsInDb[0].PublishedAt.ToString());
        }
开发者ID:WS-and-Cloud,项目名称:News-UnitTests,代码行数:19,代码来源:NewsRepositoryCrud.cs

示例5: UpdateNews_WithIncorrectData_ShouldThrow

        public void UpdateNews_WithIncorrectData_ShouldThrow()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content of new", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();
            string newTitle = null;
            newsInDb[0].Title = newTitle;
            repo.Update(newsInDb[0]);
            repo.SaveChanges();
            var latestNewsInDb = repo.All().ToArray();

            // Assert
            Assert.AreEqual(1, newsInDb.Count());
            Assert.AreEqual(new1.Title, latestNewsInDb[0].Title);
            Assert.AreEqual(new1.Content, latestNewsInDb[0].Content);
        }
开发者ID:WS-and-Cloud,项目名称:News-UnitTests,代码行数:23,代码来源:NewsRepositoryCrud.cs

示例6: GetAllNews_ShouldReturnAllNews

        public void GetAllNews_ShouldReturnAllNews()
        {
            // Arange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content 1", Title = "Title 1", PublishedAt = DateTime.Now };
            var new2 = new News() { Content = "Content 2", Title = "Title 2", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.Add(new2);
            repo.SaveChanges();

            listWithNews.Add(new1);
            listWithNews.Add(new2);

            // Assert
            Assert.AreEqual(2, repo.All().Count());
            CollectionAssert.AreEquivalent(listWithNews, repo.All().ToList());
        }
开发者ID:WS-and-Cloud,项目名称:News-UnitTests,代码行数:21,代码来源:NewsRepositoryCrud.cs


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