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


C# Repository.MakePersistent方法代码示例

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


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

示例1: InitializeData

        public void InitializeData()
        {
            using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var milk = new Customization
                   {
                     Name = "Milk",
                     PossibleValues = {"skim", "semi", "whole"}
                   };

            var size = new Customization
                   {
                     Name = "Size",
                     PossibleValues = {"small", "medium", "large"}
                   };

            var shots = new Customization
                    {
                      Name = "Shots",
                      PossibleValues = {"single", "double", "triple"}
                    };

            var whippedCream = new Customization
                           {
                             Name = "Whipped Cream",
                             PossibleValues = {"yes", "no"}
                           };

            var kindOfCookie = new Customization
                           {
                             Name = "Kind",
                             PossibleValues = {"chocolate chip", "ginger"}
                           };

            var customizationRepository = new Repository<Customization>(session);
            customizationRepository.MakePersistent(milk, size, shots, whippedCream, kindOfCookie);
            var productRepository = new Repository<Product>(session);

            var coffees = new[] {"Latte", "Capuccino", "Espresso", "Tea"}
              .Select(
            coffeName =>
            new Product {Name = coffeName, Price = (decimal) coffeName.First()/10, Customizations = {milk, size, shots}})
              .ToArray();

            productRepository.MakePersistent(coffees);

            productRepository.MakePersistent(new Product
                                         {
                                           Name = "Hot Chocolate",
                                           Price = 10.5m,
                                           Customizations = {milk, size, whippedCream}
                                         });
            productRepository.MakePersistent(new Product {Name = "Cookie", Price = 1, Customizations = {kindOfCookie}});
            tx.Commit();
              }
        }
开发者ID:grahamrhay,项目名称:Restbucks-on-Nancy,代码行数:57,代码来源:DataInitializer.cs

示例2: CanStoreOneCustomizationInTwoProducts

        public void CanStoreOneCustomizationInTwoProducts()
        {
            long customizationId;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var customizationRepository = new Repository<Customization>(session);
                var customization = new Customization { Name = "Milk", PossibleValues = { "skim", "semi", "whole" } };
                customizationRepository.MakePersistent(customization);
                customizationId = customization.Id;

                var productRepository = new Repository<Product>(session);
                productRepository.MakePersistent(new Product
                {
                    Name = "Coffee 3",
                    Price = 10.4m,
                    Customizations = { customization }
                });
                productRepository.MakePersistent(new Product { Name = "Coffee 4", Price = 5.4m, Customizations = { customization } });

                tx.Commit();
            }

            using (var session = m_sessionFactory.OpenSession())
            {
                new Repository<Product>(session)
                    .Retrieve(p => p.Customizations.Any(c => c.Id == customizationId))
                    .Count().Should().Be.EqualTo(2);
            }
        }
开发者ID:KamilLach,项目名称:RestBucks,代码行数:30,代码来源:DataTests.cs

示例3: CanStoreAProduct

        public void CanStoreAProduct()
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<CoffeeShopContext>());
            long id;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var repository = new Repository<Product>(session);
                var product = new Product
                {
                    Name = "Coffee 1",
                    Price = 10.4m
                };

                repository.MakePersistent(product);
                id = product.Id;
                tx.Commit();
            }

            using (var session = m_sessionFactory.OpenSession())
            using (session.BeginTransaction())
            {
                var repository = new Repository<Product>(session);
                Product product = repository.GetById(id);

                product.Satisfy(p => p.Name == "Coffee 1" && p.Price == 10.4m);
            }
        }
开发者ID:KamilLach,项目名称:RestBucks,代码行数:28,代码来源:DataTests.cs

示例4: InsertingShouldWork

        public void InsertingShouldWork()
        {
            var cudGroup = new Repository<Group>(connectionString);
            var entity = new Group{Name = "Test", Description = "Abcd"};
            cudGroup.MakePersistent(entity);

            mongoDb.GetCollection(MongoDbConstants.Collections.Groups)
                .FindOneById(entity.Id.Value.ToBson())
                .Should().Not.Be.Null();
        }
开发者ID:jasondentler,项目名称:Hermes,代码行数:10,代码来源:CudGroupsTests.cs

示例5: CanStoreACustomization

 public void CanStoreACustomization()
 {
     long customizationId;
     using (var session = m_sessionFactory.OpenSession())
     using(var tx = session.BeginTransaction())
     {
         var repository = new Repository<Customization>(session);
         var customization = new Customization { Name = "Milk", PossibleValues = { "skim", "semi", "whole" } };
         repository.MakePersistent(customization);
         customizationId = customization.Id;
         tx.Commit();
     }
     using (var session = m_sessionFactory.OpenSession())
     {
         var repository = new Repository<Customization>(session);
         Customization readed = repository.GetById(customizationId);
         readed.Satisfy(c => c.Name == "Milk" && c.PossibleValues.SequenceEqual(new[] { "skim", "semi", "whole" }));
     }
 }
开发者ID:KamilLach,项目名称:RestBucks,代码行数:19,代码来源:DataTests.cs

示例6: CanStoreAnOrderWithPayment

        public void CanStoreAnOrderWithPayment()
        {
            long id;
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var productRepository = new Repository<Product>(session);
            var product = new Product {Name = "Latte", Price = 10.4m};
            productRepository.MakePersistent(product);

            var orderRepository = new Repository<Order>(session);
            var order = new Order
                    {
                      Date = new DateTime(2011, 1, 1),
                      Location = Location.InShop,
                    };
            order.AddItem(new OrderItem
                      {
                        Product = product,
                        UnitPrice = 10.4m,
                        Preferences =
                          {
                            {"Milk", "skim"},
                            {"Size", "small"}
                          }
                      });
            orderRepository.MakePersistent(order);
            order.Pay("1234", "jose");
            id = order.Id;
            tx.Commit();
              }

              using (var context = sessionFactory.OpenSession())
              {
            var repository = new Repository<Order>(context);
            var order = repository.GetById(id);
            order.Satisfy(o => o.Location == Location.InShop
                           && o.Items.Count() == 1
                           && o.Payment != null);
              }
        }
开发者ID:grahamrhay,项目名称:Restbucks-on-Nancy,代码行数:41,代码来源:OrderTests.cs

示例7: CanChangeStatus

        public void CanChangeStatus()
        {
            long id;
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var productRepository = new Repository<Product>(session);
            var product = new Product {Name = "Latte", Price = 10.4m};
            productRepository.MakePersistent(product);

            var orderRepository = new Repository<Order>(session);
            var order = new Order
                    {
                      Date = new DateTime(2011, 1, 1),
                      Location = Location.InShop,
                    };
            order.AddItem(new OrderItem
                      {
                        Product = product,
                        UnitPrice = 10.4m,
                        Preferences =
                          {
                            {"Milk", "skim"},
                            {"Size", "small"}
                          }
                      });
            orderRepository.MakePersistent(order);
            order.Cancel("cascasas");
            id = order.Id;
            tx.Commit();
              }
              using (var session = sessionFactory.OpenSession())
              using (session.BeginTransaction())
              {
            session.Get<Order>(id).Status.Should().Be.EqualTo(OrderStatus.Canceled);
              }
        }
开发者ID:grahamrhay,项目名称:Restbucks-on-Nancy,代码行数:37,代码来源:OrderTests.cs

示例8: CanStoreTwoProducts

        public void CanStoreTwoProducts()
        {
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var repository = new Repository<Product>(session);

                repository.MakePersistent(new Product { Name = "Coffee 3", Price = 10.4m });
                repository.MakePersistent(new Product { Name = "Coffee 4", Price = 5.4m });

                tx.Commit();
            }
        }
开发者ID:KamilLach,项目名称:RestBucks,代码行数:13,代码来源:DataTests.cs

示例9: VersionNumberGrowOnEachUpdate

        public void VersionNumberGrowOnEachUpdate()
        {
            long id;
              int version;
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var productRepository = new Repository<Product>(session);
            var product = new Product {Name = "Latte", Price = 10.4m};
            productRepository.MakePersistent(product);

            var orderRepository = new Repository<Order>(session);
            var order = new Order
                    {
                      Date = new DateTime(2011, 1, 1),
                      Location = Location.InShop,
                    };
            order.AddItem(new OrderItem
                      {
                        Product = product,
                        UnitPrice = 10.4m,
                        Preferences =
                          {
                            {"Milk", "skim"},
                            {"Size", "small"}
                          }
                      });
            orderRepository.MakePersistent(order);
            order.Pay("1234", "jose");
            id = order.Id;

            tx.Commit();
            version = order.Version;
              }
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var order = session.Get<Order>(id);
            order.Location = Location.TakeAway;
            tx.Commit();

            order.Version.Should().Be.GreaterThan(version);
              }
        }
开发者ID:grahamrhay,项目名称:Restbucks-on-Nancy,代码行数:44,代码来源:OrderTests.cs

示例10: CanStoreAOrder

        public void CanStoreAOrder()
        {
            long id;
            using (var session = m_sessionFactory.OpenSession())
            using(var tx = session.BeginTransaction())
            {
                var productRepository = new Repository<Product>(session);
                var product = new Product { Name = "Latte", Price = 10.4m };
                productRepository.MakePersistent(product);

                var orderRepository = new Repository<Order>(session);
                var order = new Order
                {
                    Date = new DateTime(2011, 1, 1),
                    Location = Location.InShop
                };

                order.AddItem(new OrderItem
                                  {
                                      Product = product,
                                      UnitPrice = 10.4m,
                                      Preferences =
                                          {
                                              {"Milk", "skim"},
                                              {"Size", "small"}
                                          }
                                  });

                order.AddItem(new OrderItem
                                {
                                    Product = product,
                                    UnitPrice = 10.4m,
                                    Preferences = { { "Shots", "single" } }
                                });

                orderRepository.MakePersistent(order);
                id = order.Id;
                tx.Commit();
            }

            using (var context = m_sessionFactory.OpenSession())
            {
                var repository = new Repository<Order>(context);
                var order = repository.GetById(id);
                order.Satisfy(a_o => a_o.Location == Location.InShop
                                && a_o.Items.Count() == 2
                                && a_o.Items.Any(a_i => a_i.Preferences.ContainsKey("Shots"))
                                && a_o.Items.Any(a_i => a_i.Preferences.ContainsKey("Milk") && a_i.Preferences.ContainsKey("Size")));
            }
        }
开发者ID:hakeemsm,项目名称:RestBucks,代码行数:50,代码来源:OrderTests.cs


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