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


C# Repository.Delete方法代码示例

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


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

示例1: BasicCrud

        public void BasicCrud()
        {
            using (var trans = DataSource.BeginTransaction())
            {

                var repo = new Repository<Employee, int>(trans, EmployeeTableName);

                var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
                var echo1 = repo.Insert(emp1);

                Assert.AreNotEqual(0, echo1.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp1.FirstName, echo1.FirstName, "FirstName");
                Assert.AreEqual(emp1.LastName, echo1.LastName, "LastName");
                Assert.AreEqual(emp1.Title, echo1.Title, "Title");

                echo1.MiddleName = "G";
                repo.Update(echo1);

                var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = echo1.EmployeeKey };
                var echo2 = repo.Insert(emp2);
                Assert.AreNotEqual(0, echo2.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp2.FirstName, echo2.FirstName, "FirstName");
                Assert.AreEqual(emp2.LastName, echo2.LastName, "LastName");
                Assert.AreEqual(emp2.Title, echo2.Title, "Title");
                Assert.AreEqual(emp2.ManagerKey, echo2.ManagerKey, "ManagerKey");

                var list = repo.GetAll();
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo1.EmployeeKey), "Employee 1 is missing");
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo2.EmployeeKey), "Employee 2 is missing");

                var get1 = repo.Get(echo1.EmployeeKey.Value);
                Assert.AreEqual(echo1.EmployeeKey, get1.EmployeeKey);



                var whereSearch1 = repo.Query("FirstName = @FN", new { FN = "Tom" });
                Assert.IsTrue(whereSearch1.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch1.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");

                var whereSearch2 = repo.Query(new { FirstName = "Tom" });
                Assert.IsTrue(whereSearch2.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch2.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");


                repo.Delete(echo2.EmployeeKey.Value);
                repo.Delete(echo1.EmployeeKey.Value);

                var list2 = repo.GetAll();
                Assert.AreEqual(list.Count - 2, list2.Count);

                trans.Commit();
            }

        }
开发者ID:docevaad,项目名称:Chain,代码行数:54,代码来源:TransactionalRepositoryTests.cs

示例2: DeleteArticle

 public void DeleteArticle(Article article)
 {
     using (var repository1 = new Repository())
     {
         repository1.Delete(article);
     }
 }
开发者ID:Nerielle,项目名称:Learning,代码行数:7,代码来源:HomeController.cs

示例3: About

        public ActionResult About()
        {
            // Generiskt Repository - Här skapas ett repository för Category
            // Repositoryt kräver typer som implementerar IEntity
            Repository<Category> categoryRepo = new Repository<Category>();

            // Samtliga metoder som finns med i det generiska repositoriet
            var categories = categoryRepo.FindAll();

            var filteredCategories = categoryRepo.FindAll(c => c.Name.Contains("sport"));

            var category = categoryRepo.FindByID(0);

            category.Name = "New Name!";
            categoryRepo.Save(category);

            categoryRepo.Delete(category);

            ProductRepository productRepo = new ProductRepository();

            var products = productRepo.FindAll(); // + övriga "grund"-metoder

            // Metoder implementerade i ProductRepository:
            var productsForCategory = productRepo.FindProductsByCategoryID(0);

            var productsWithEmptyName = productRepo.FindAll(ProductRepository
                                                            .FilterProductsWithEmptyDescription);

            return View();
        }
开发者ID:awt2gbg2012,项目名称:Lektion13,代码行数:30,代码来源:HomeController.cs

示例4: DeleteComment

 public void DeleteComment(Comment comment)
 {
     using (var repository1 = new Repository())
     {
         repository1.Delete(comment);
     }
 }
开发者ID:Nerielle,项目名称:Learning,代码行数:7,代码来源:HomeController.cs

示例5: ShouldDelete

        public void ShouldDelete()
        {
            // arrange
            Repository<string> r = new Repository<string>(m_session.Object);
            string s = "this";

            // act
            r.Delete(s);

            // assert
            m_session.Verify(x => x.Delete((object)s));
        }
开发者ID:triggerfish,项目名称:Common,代码行数:12,代码来源:RepositoryTests.cs

示例6: Main

        static void Main(string[] args)
        {
            var soapShopDb = new SoapShopDb();
            var component = new Repository(soapShopDb);

            // Adding some entity
            component.Add(new Customer { CustomerName = "Nata", CustomerPhone = "679011198" });
            component.Save();
            component.Add(new SoapProduct { Tittle = "Eucalyptus", Mass = 100, Price = 25.2M });
            component.Save();

            // Delating some entity
            var comp = soapShopDb.Set<Customer>().FirstOrDefault(i => i.CustomerName == "Nata");
            component.Delete(comp);
            component.Save();

            // Reading some entity
            var list = component.Get<Customer>();
            foreach (var item in list)
            {
                Console.WriteLine(item.Id + " " + item.CustomerName + " " + item.CustomerPhone + "\n");
            }

            // Find one
            var comp2 = component.Get<Customer>(3);
            Console.WriteLine(comp2.CustomerName);
        }
开发者ID:Gorova,项目名称:task3,代码行数:27,代码来源:Program.cs

示例7: Should_throw_ArgumentNullException_if_null_passed_in

 public void Should_throw_ArgumentNullException_if_null_passed_in()
 {
     using (var context = new RepositoryTestDataContext())
     {
         var repo = new Repository<Order>(context);
         Assert.Throws<ArgumentNullException>(() => repo.Delete(null));
     }
 }
开发者ID:NathanGloyn,项目名称:Generic-Repository,代码行数:8,代码来源:When_deleting_a_record.cs

示例8: Delete

 public void Delete(string slug)
 {
     using (var repository = new Repository<Entry>())
     {
         var entry = repository.Find(slug);
         repository.Delete(entry);
     }
 }
开发者ID:niekert,项目名称:GoBlog,代码行数:8,代码来源:EntryService.cs

示例9: TestDeleteWorks

        public void TestDeleteWorks()
        {
            Repository repository = new Repository(new SqlConnectionDev());
            Club club = new Club();
            club.clubId = 1;
            bool result = repository.Delete(club);

            Assert.IsNotNull(result);
        }
开发者ID:chao226,项目名称:Dapper.Repository,代码行数:9,代码来源:UnitTest1.cs

示例10: SetUp

 public void SetUp()
 {
     //_repository = A.Fake<IRepository<Category>>();
     _repository = new Repository<Category>(() => new JudgifyContext());
     foreach (var category in _repository.GetAll())
     {
         _repository.Delete(category);
     }
 }
开发者ID:Judgify,项目名称:judgify-gft-project,代码行数:9,代码来源:RepositoryTests.cs

示例11: DeleteEducation

 public void DeleteEducation()
 {
     var repo = new Repository<EducationModel>(DbCollection.Education);
     var contacts = repo.Gets().Where(m => m.UserId == "5709a5b24a549a1a9873a19b");
     foreach (var item in contacts)
     {
         repo.Delete(item.Id);
     }
 }
开发者ID:xuantranm,项目名称:DigitalMarket,代码行数:9,代码来源:Common.cs

示例12: DeleteTestAggregate

        internal void DeleteTestAggregate(TestAggregate aggregate)
        {
            var repository = new Repository<TestAggregate, TestEntity>();
            using (var unitOfWork = new UnitOfWorkFactory(TestSettings.BoilerMongoConfiguration).CreateUnitOfWork())
            {
                repository.UnitOfWork = unitOfWork;
                repository.Delete(aggregate);

                unitOfWork.Commit();
            }
        }
开发者ID:onatm,项目名称:Boilerplate.Persistence.Mongo,代码行数:11,代码来源:AggregateHelper.cs

示例13: Delete

 public ActionResult Delete(string id, AdminSetting model)
 {
     try
     {
         var repo = new Repository<AdminSetting>(DbCollection.AdminSetting);
         repo.Delete(new ObjectId(id));
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
开发者ID:xuantranm,项目名称:DigitalMarket,代码行数:13,代码来源:AdminSettingController.cs

示例14: Should_Delete_An_Entity

        public void Should_Delete_An_Entity()
        {
            var repository = new Repository<Author>();
            var author = repository.Insert(new Author()
            {
                FirstName = "Bruce",
                LastName = "Wayne"
            });

            repository.Delete(author.Id);
            author = repository.GetById(author.Id);
            Assert.IsNull(author);
        }
开发者ID:nicolasmetaye,项目名称:DynamicLoopMVC,代码行数:13,代码来源:RepositoryTests.cs

示例15: Add_User_Fails_If_UserName_Not_Unique

        public void Add_User_Fails_If_UserName_Not_Unique()
        {
            string userName = Guid.NewGuid().ToString();
            User user1 = new User
                            {
                                FirstName = "First",
                                LastName = "User1",
                                UserName = userName,
                                Email = "[email protected]"
                            };
            User user2 = new User
            {
                FirstName = "Second",
                LastName = "User2",
                UserName = userName,
                Email = "[email protected]"
            };

            NHibernateHelper helper = new NHibernateHelper();

            // create
            using (UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory))
            {
                Repository<User> userRepo = new Repository<User>(unitOfWork.Session);
                Assert.IsTrue(userRepo.Add(user1));
                unitOfWork.Commit();
            }
            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory))
                {
                    Repository<User> userRepo = new Repository<User>(unitOfWork.Session);
                    Assert.IsTrue(userRepo.Add(user2));
                    unitOfWork.Commit();
                }
            }
            catch (NHibernate.Exceptions.GenericADOException ex)
            {
                // expected this
            }
            finally
            {
                // delete
                using (UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory))
                {
                    Repository<User> userRepo = new Repository<User>(unitOfWork.Session);
                    Assert.IsTrue(userRepo.Delete(user1));
                    unitOfWork.Commit();
                }
            }
        }
开发者ID:dheindel,项目名称:gpsnerd,代码行数:51,代码来源:RepositoryTests.cs


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