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


C# GenericRepository.Delete方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            var contactsRepository = new GenericRepository<Contact>();

            contactsRepository.Delete(5);

            //for (int i = 0; i < 1000; i++)
            //{
            //    var currentContact = new Contact();
            //    currentContact.FirstName = "ContactFirstName" + i;
            //    currentContact.LastName = "ContactLastName" + i;

            //    if (i % 3 == 0)
            //    {
            //        currentContact.Sex = Sex.Male;
            //        currentContact.Status = Status.Active;
            //    }
            //    else if (i % 3 == 1)
            //    {
            //        currentContact.Sex = Sex.Female;
            //        currentContact.Status = Status.Inactive;
            //    }
            //    else
            //    {
            //        currentContact.Sex = Sex.Other;
            //        currentContact.Status = Status.Deleted;
            //    }

            //    Random rand = new Random();
            //    currentContact.Telephone = rand.Next(1000000000, 2000000000).ToString();

            //    contactsRepository.Add(currentContact);
            //}
        }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:34,代码来源:Program.cs

示例2: DoObsolete

        public ActionResult DoObsolete(int id)
        {
            try
            {
                var repository = new GenericRepository<Media>(Db);
                var model = repository.FindById(id);
                if (model == null)
                {
                    return Json(new ResponseMessageModel
                    {
                        HasError = false,
                        Title = ResShared.TITLE_OBSOLETE_FAILED,
                        Message = ResShared.ERROR_MODEL_NOTFOUND
                    });
                }

                repository.Delete(model);

                return Json(new ResponseMessageModel
                {
                    HasError = false,
                    Title = ResShared.TITLE_OBSOLETE_SUCCESS,
                    Message = ResShared.INFO_REGISTER_DELETED
                });

            }
            catch (Exception ex)
            {
                SharedLogger.LogError(ex, id);
                return Json(new ResponseMessageModel
                {
                    HasError = true,
                    Title = ResShared.TITLE_OBSOLETE_FAILED,
                    Message = ResShared.ERROR_REGISTER_CANNOT_DELETE
                });
            }
        }
开发者ID:stphosvsol,项目名称:SignageDigitalPortal,代码行数:37,代码来源:MediaController.cs

示例3: DeleteNews_Should_Throw_Exeption_If_Object_Of_Deletion_Is_Invalid

        public void DeleteNews_Should_Throw_Exeption_If_Object_Of_Deletion_Is_Invalid()
        {
            var repository = new GenericRepository<News>(new NewsContext());

            var newsToDelete = new News
            {
                Title = "Update aaa",
                Content = "Update aaa",
                PublishDate = DateTime.Now
            };

            repository.Delete(newsToDelete);
            repository.SaveChanges();
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:14,代码来源:RepositoryTests.cs

示例4: DeleteNews_Should_Successfully_Delete_Object_If_It_Exists

        public void DeleteNews_Should_Successfully_Delete_Object_If_It_Exists()
        {
            var repository = new GenericRepository<News>(new NewsContext());

            var newsModel = repository.All().FirstOrDefault();
            if (newsModel == null)
            {
                Assert.Fail("Cannot perform test - Unable to delete unexisting object.");
            }

            repository.Delete(newsModel);
            repository.SaveChanges();
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:13,代码来源:RepositoryTests.cs

示例5: Delete_Existing_Id_MUST_Delete

        public void Delete_Existing_Id_MUST_Delete()
        {
            //
            // Arrange
            //
            var mockModel = new Mock<IModel>();
            var mockDbSet = new Mock<DbSet<IModel>>();
            mockDbSet.Setup(x => x.Find(It.IsAny<object[]>())).Returns<object[]>(x =>
            {
                return mockModel.Object;
            });

            var mockContext = new Mock<EFDbContext>();
            mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object);
            mockContext.Setup(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>())).Callback<object, RecordState>((obj, state) =>
            {
                return;
            });

            var repository = new GenericRepository<IModel>(mockContext.Object);
            //
            // Act
            //
            repository.Delete(1);
            //
            // Assert
            //
            mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Once);
        }
开发者ID:Cheranga,项目名称:DAL,代码行数:29,代码来源:GenericRepositoryTest.cs

示例6: Update_UnExisting_Object_Must_NOT_Update

        public void Update_UnExisting_Object_Must_NOT_Update()
        {
            //
            // Arrange
            //
            var mockModel = new Mock<IModel>();
            var mockDbSet = new Mock<DbSet<IModel>>();
            mockDbSet.Setup(x => x.Find(It.IsAny<object[]>())).Returns<object[]>(x =>
            {
                return null;
            });

            var mockContext = new Mock<EFDbContext>();
            mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object);

            var repository = new GenericRepository<IModel>(mockContext.Object);
            //
            // Act
            //
            repository.Delete(mockModel.Object);
            //
            // Assert
            //
            mockDbSet.Verify(x => x.Find(It.IsAny<object[]>()), Times.Once);
            mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Never);
        }
开发者ID:Cheranga,项目名称:DAL,代码行数:26,代码来源:GenericRepositoryTest.cs

示例7: Delete_NULL_Object_Must_NOT_Delete

        public void Delete_NULL_Object_Must_NOT_Delete()
        {
            //
            // Arrange
            //
            var mockDbSet = new Mock<DbSet<IModel>>();

            var mockContext = new Mock<EFDbContext>();
            mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object);

            var repository = new GenericRepository<IModel>(mockContext.Object);
            //
            // Act
            //
            repository.Delete(null);
            //
            // Assert
            //
            mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Never);
        }
开发者ID:Cheranga,项目名称:DAL,代码行数:20,代码来源:GenericRepositoryTest.cs

示例8: Can_Remove_Entity_By_Predicate

        public void Can_Remove_Entity_By_Predicate()
        {
            // Arrange
            var routesRepository = new GenericRepository<Route>(this.dataBaseContext);

            // Act
            routesRepository.Delete(x => x.Id == 2);

            // Assert
            Assert.AreEqual(1, routesRepository.Count);
            Assert.AreEqual(null, routesRepository.GetById(2));
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:12,代码来源:GenericRepositoryTests.cs

示例9: Can_Remove_Entity_By_It_Specifying

        public void Can_Remove_Entity_By_It_Specifying()
        {
            // Arrange
            var routesRepository = new GenericRepository<Route>(this.dataBaseContext);
            var entityToDelete = routesRepository.GetById(2);

            // Act
            routesRepository.Delete(entityToDelete);

            // Assert
            Assert.AreEqual(1, routesRepository.Count);
            Assert.AreEqual(null, routesRepository.GetById(2));
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:13,代码来源:GenericRepositoryTests.cs

示例10: DeleteMovieWhenExistingItemShouldDelete

        public void DeleteMovieWhenExistingItemShouldDelete()
        {
            //Arrange -> prepare the objects
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var movie = new Movie()
            {
                Id = 1,
                Length = 10,
                Ration = 10
            };

            //Act -> perform some logic
            repo.Add(movie);
            repo.SaveChanges();

            var movieFromDb = repo.GetById(movie.Id);

            repo.Delete(movieFromDb);
            repo.SaveChanges();

            var newMovieFromDb = repo.GetById(movie.Id);
            
            //Asssert -> expect and exception
            Assert.IsNull(newMovieFromDb);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:25,代码来源:RepositoeisTest.cs

示例11: DeleteMovieWhenNotExistShouldThrowException

        public void DeleteMovieWhenNotExistShouldThrowException()
        {
            //Arrange -> prepare the objects
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var movie = repo.GetById(234);
            repo.Delete(movie);

        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:8,代码来源:RepositoeisTest.cs


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