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


C# EFRepository.Insert方法代码示例

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


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

示例1: InsertUserTest

 public void InsertUserTest()
 {
     EFRepository<GazallionMigraineDataDbContext> repo = new EFRepository<GazallionMigraineDataDbContext>();
     User test = repo.Insert<User>(new User
     {
         FirstName = "John",
         LastName = "Nystrom",
         Addresses = new List<Address>
         {
             new Address
             {
                 City = "Alpharetta",
                 Region = "GA",
                 ZipCode = "30004",
                 StreetName = "Montgomery Ave",
                 StreetNumber = "123"
             }
         },
         EmailAddress = "[email protected]",
         UserConditions = new List<UserCondition>
         {
             new UserCondition
             {
                 Condition = new Condition
                 {
                     Name = "Migraine",
                     Description = "bad headaches"
                 },
                 IncidentThreshold = 9,
                 ThresholdTimePeriod = (int)ThresholdTimePeriod.Monthly
             }
         }
     });
 }
开发者ID:jnystrom,项目名称:migrainetracker,代码行数:34,代码来源:UnitTest1.cs

示例2: addElement

        public void addElement()
        {
            var repository = new EFRepository<User>(new SystemOfFinancialContext());
            repository.Insert(new User(){FirstName = "Flyagin"});

            Assert.NotNull(repository.Get(x=>x.FirstName=="Flyagin"));
        }
开发者ID:Panya911,项目名称:system-of-financial-vote,代码行数:7,代码来源:GenericRepositoryTests.cs

示例3: TestMethod1

        public void TestMethod1()
        {
            EFRepository<GazallionMigraineDataDbContext> repo = new EFRepository<GazallionMigraineDataDbContext>();
            Medicine test = repo.Insert<Medicine>(new Medicine
            {
                MedType = new MedType
                {
                    Type = "daily"
                },
                Name = "Topomax",

            });
        }
开发者ID:jnystrom,项目名称:migrainetracker,代码行数:13,代码来源:UnitTest1.cs

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

示例5: InsertIsOK

  public void InsertIsOK()
  {
 
      var context = new CarContext();
      var testContext = new EFRepository<Car,int>(context);
      var all = context.Car.ToList();
      all.ForEach(r => testContext.Delete(r));
      testContext.Save();
      Assert.AreEqual(context.Car.ToList().Count, 0);
      testContext.Insert(new Car()
      {
          CarName = "Ford",
          CarPrice = 100000
      });
      testContext.Save();
      var cars = context.Car.ToList();
      Assert.AreEqual(testContext.Count(), 1);
      Assert.AreEqual(testContext.Get(r => r.CarPrice == 100000).CarName, "Ford");
  }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:19,代码来源:UnitTest2.cs

示例6: Test_Sample

        public void Test_Sample()
        {
            IDbContext db = new R2DisasterContext();
            IRepository<Category> re = new EFRepository<Category>(db);

            Category c = new Category()
            {   
                Name = "Testname",
                Book = new Book()
                {
                    Name="TestBook",
                    Price=333
                }
            };
            re.Insert(c);
        }
开发者ID:hiyouth,项目名称:R2.DisasterWebAPI,代码行数:16,代码来源:InitDataTemp.cs

示例7: UpdateIsOK

        public void UpdateIsOK()
        {
            var context = new CarContext();
            var testContext = new EFRepository<Car,int>(context);
            var all = context.Car.ToList();
            all.ForEach(r => testContext.Delete(r));
            testContext.Save();
            var car = new Car()
            {
                CarName = "Ford",
                CarPrice = 100000
            };
            testContext.Insert(car);
            testContext.Save();

            car.CarName = "Ford1";
            car.CarPrice = 100000 - 1;
            testContext.Update(car);
            testContext.Save();

            var cars = context.Car.ToList();
            Assert.AreEqual(cars.Count, 1);
            Assert.AreEqual(cars.FirstOrDefault().CarName, "Ford1");
            Assert.AreEqual(cars.FirstOrDefault().CarPrice, 100000 - 1);
        }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:25,代码来源:UnitTest2.cs

示例8: MyTestMethod

        public void MyTestMethod()
        {
            var context = new CarContext();
            var testContext = new EFRepository<Car, int>(context);
            context.Car.ToList().ForEach(r => testContext.Delete(r));
            testContext.Save();
            var car = new Car()
            {
                CarName = "Ford",
                CarPrice = 100000
            };
            var car1 = new Car()
            {
                CarName = "Toyota",
                CarPrice = 100000
            };
            testContext.Insert(car);
            testContext.Insert(car1);
            testContext.Save();

            //var cars = testContext.GetList();
            //Assert.AreEqual(cars.Count, 1);
            //Assert.AreEqual(cars.FirstOrDefault().CarName, "Ford");
            //Assert.AreEqual(cars.FirstOrDefault().CarPrice, 100000);
        }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:25,代码来源:UnitTest2.cs

示例9: GetAllOrderByIsOK

 public void GetAllOrderByIsOK()
 {
     var context = new CarContext();
     var testContext = new EFRepository<Car,int>(context);
     context.Car.ToList().ForEach(r => testContext.Delete(r));
     testContext.Save();
     var car = new Car()
     {
         CarName = "Ford",
         CarPrice = 100000
     };
     var car1 = new Car()
     {
         CarName = "Toyota",
         CarPrice = 99999
     };
     testContext.Insert(car);
     testContext.Insert(car1);
     testContext.Save();
     var cars = testContext.GetList(r => r.CarPrice == 100000, null, "").ToList();
     Assert.AreEqual(cars.Count, 1);
     Assert.AreEqual(cars.FirstOrDefault().CarName, "Ford");
     Assert.AreEqual(cars.FirstOrDefault().CarPrice, 100000);
 }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:24,代码来源:UnitTest2.cs

示例10: Delete1IsOK

 public void Delete1IsOK()
 {
     var context = new CarContext();
     var testContext = new EFRepository<Car,int>(context);
     var all = context.Car.ToList();
     all.ForEach(r => testContext.Delete(r));
     testContext.Save();
     var car = new Car()
     {
         CarName = "Ford",
         CarPrice = 100000
     };
     testContext.Insert(car);
     testContext.Save();
     testContext.Delete(r => r.ID == car.ID);
     testContext.Save();
     var cars = context.Car.ToList();
     Assert.AreEqual(cars.Count, 0);
 }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:19,代码来源:UnitTest2.cs

示例11: Update1IsOK

        public void Update1IsOK()
        {
            var context = new CarContext();
            var testContext = new EFRepository<Car,int>(context);
            var all = context.Car.ToList();
            all.ForEach(r => testContext.Delete(r));
            testContext.Save();
            var car = new Car()
            {
                CarName = "Ford",
                CarPrice = 100000
            };
            testContext.Insert(car);
            testContext.Save();
            car.CarPrice = 99999;
            car.CarName = "Ford1";
            testContext.Update(car, x => new { x.CarPrice });
            testContext.Save();
            var cars = testContext.GetDbSet().AsNoTracking().ToList();//OK


            var cars1 = testContext.GetDbSet().ToList();//error            
            Assert.AreEqual(cars.Count, 1);
            Assert.AreEqual(cars.FirstOrDefault().CarName, "Ford");
            Assert.AreEqual(cars.FirstOrDefault().CarPrice, 100000 - 1);
        }
开发者ID:Indifer,项目名称:Raven.EntityFramework.Repository,代码行数:26,代码来源:UnitTest2.cs


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