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


C# Session.Add方法代码示例

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


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

示例1: DbRefMapsToOtherDocumentsByOid

        public void DbRefMapsToOtherDocumentsByOid()
        {
            const string databaseName = "NormTests";
            var id = ObjectId.NewObjectId();

            using (var session = new Session())
            {
                session.Drop<Product>();
                session.Drop<ProductReference>();

                session.Add(new Product { _id = id, Name = "RefProduct" });

                var productReference = new DbReference<Product>(id);

                session.Add(new ProductReference
                    {
                        Id = ObjectId.NewObjectId(),
                        Name = "FullCart",
                        ProductsOrdered = new[] { productReference }
                    });
            }

            var server = Mongo.Create("mongodb://localhost/" + databaseName);
            var reference = server.GetCollection<ProductReference>().Find().First();
            var product = reference.ProductsOrdered[0].Fetch(() => server);

            Assert.Equal(id.Value, product._id.Value);
        }
开发者ID:perikete,项目名称:NoRM,代码行数:28,代码来源:DBRefTests.cs

示例2: DBRefMapsToOtherDocumentsByOid

        public void DBRefMapsToOtherDocumentsByOid()
        {
            var id = ObjectId.NewObjectId();

            using (var session = new Session())
            {
                session.Add(new Product { Id = id, Name = "RefProduct" });

                var productReference = new DBReference
                                           {
                                               Collection = MongoConfiguration.GetCollectionName(typeof(Product)),
                                               DatabaseName = "test",
                                               ID = id,
                                           };

                session.Add(new ProductReference
                                {
                                    Id = ObjectId.NewObjectId(),
                                    Name = "FullCart",
                                    ProductsOrdered = new[] { productReference }
                                });
            }

            var server = Mongo.ParseConnection("mongodb://localhost/NoRMTests");
            var reference = server.GetCollection<ProductReference>().Find().First();
            var product = reference.ProductsOrdered[0].Fetch(() => GetReferenceCollection());

            Assert.Equal(id.Value, product.Id.Value);
        }
开发者ID:kenegozi,项目名称:NoRM,代码行数:29,代码来源:DBRefTests.cs

示例3: DbRefMapsToOtherDocumentsByCustomId

        public void DbRefMapsToOtherDocumentsByCustomId()
        {
            const string databaseName = "NormTests";
            const string userId = "Tim Berners-Lee";
            const string roleName = "Administrator";

            using (var session = new Session())
            {
                session.Drop<User>();
                session.Drop<Role>();

                session.Add(new User
                                {
                                    Id = userId,
                                    EmailAddress = "[email protected]"
                                });
                session.Add(new Role
                                {
                                    Id = roleName,
                                    Users = new List<DbReference<User, string>>
                                                {
                                                    new DbReference<User, string>(userId)
                                                }
                                });
            }

            var server = Mongo.Create("mongodb://localhost/" + databaseName);
            var role = server.GetCollection<Role>().Find().First();
            var user = role.Users[0].Fetch(() => server);

            Assert.Equal(userId, user.Id);
        }
开发者ID:perikete,项目名称:NoRM,代码行数:32,代码来源:DBRefTests.cs

示例4: AnyShouldReturnTrueWhenProductPrice10

        public void AnyShouldReturnTrueWhenProductPrice10()
        {
            using (var session = new Session()) {
                session.Add(new Product { Name = "1", Price = 10 });
                session.Add(new Product { Name = "2", Price = 20 });
                session.Add(new Product { Name = "3", Price = 30 });

                Assert.True(session.Products.Any(x=>x.Price==10));
            }
        }
开发者ID:kenegozi,项目名称:NoRM,代码行数:10,代码来源:LinqAggregates.cs

示例5: OneProductsShouldBeReturnedWhen3InDbWithPriceEqual10

 public void OneProductsShouldBeReturnedWhen3InDbWithPriceEqual10()
 {
     using (var session = new Session()) {
         session.Add(new Product { Name = "Test3", Price = 10 });
         session.Add(new Product { Name = "Test4", Price = 22 });
         session.Add(new Product { Name = "Test5", Price = 33 });
         var products = session.Products.Where(x => x.Price ==10).ToList();
         Assert.Equal(1, products.Count);
     }
 }
开发者ID:zeya,项目名称:NoRM,代码行数:10,代码来源:LinqTests.cs

示例6: CountShouldReturn2WhenThreeProductsInDBAndWherePriceGreaterThan20

 public void CountShouldReturn2WhenThreeProductsInDBAndWherePriceGreaterThan20()
 {
     using (var session = new Session()) {
         session.Add(new Product { Name = "1", Price = 10 });
         session.Add(new Product { Name = "2", Price = 22 });
         session.Add(new Product { Name = "3", Price = 33 });
         var result = session.Products.Where(x=>x.Price>20).Count();
         Assert.Equal(2, result);
     }
 }
开发者ID:kenegozi,项目名称:NoRM,代码行数:10,代码来源:LinqAggregates.cs

示例7: AvgShouldReturn20WhenThreeProductsInDBWIthSumPrice60

 public void AvgShouldReturn20WhenThreeProductsInDBWIthSumPrice60()
 {
     using (var session = new Session()) {
         session.Add(new Product { Name = "1", Price = 10 });
         session.Add(new Product { Name = "2", Price = 20 });
         session.Add(new Product { Name = "3", Price = 30 });
         var result = session.Products.Average(x => x.Price);
         Assert.Equal(20, result);
     }
 }
开发者ID:kenegozi,项目名称:NoRM,代码行数:10,代码来源:LinqAggregates.cs

示例8: OneProductShouldBeReturnedWhen3InDbWithSingle

 public void OneProductShouldBeReturnedWhen3InDbWithSingle()
 {
     using (var session = new Session())
     {
         session.Add(new Product {Name = "Test1", Price = 10});
         session.Add(new Product {Name = "Test2", Price = 22});
         session.Add(new Product {Name = "Test3", Price = 33});
         var result = session.Products.SingleOrDefault(x => x.Price == 22);
         Assert.Equal(22, result.Price);
     }
 }
开发者ID:zeya,项目名称:NoRM,代码行数:11,代码来源:LinqTests.cs

示例9: OneProductShouldBeReturnedWhenNestedSupplierQueried

 public void OneProductShouldBeReturnedWhenNestedSupplierQueried()
 {
     using (var session = new Session())
     {
         session.Add(new TestProduct { Name = "Test3", Price = 10, Supplier = new Supplier { Name = "Steve" } });
         session.Add(new TestProduct { Name = "Test4", Price = 22 });
         session.Add(new TestProduct { Name = "Test5", Price = 33 });
         var products = session.Products.Where(x => x.Supplier.Name == "Steve").ToList();
         Assert.Equal(1, products.Count);
     }
 }
开发者ID:ereichert,项目名称:NoRM,代码行数:11,代码来源:LinqDeepGraph.cs

示例10: LastTwoProductsofThreeShouldBeReturnedWithSkipTake

 public void LastTwoProductsofThreeShouldBeReturnedWithSkipTake()
 {
     using (var session = new Session()) {
         session.Add(new Product { Name = "Test1", Price = 10 });
         session.Add(new Product { Name = "Test2", Price = 22 });
         session.Add(new Product { Name = "Test3", Price = 33 });
         var products = session.Products.Skip(1).Take(2).ToList();
         Assert.Equal(22.0, products[0].Price);
         Assert.Equal(33.0, products[1].Price);
     }
 }
开发者ID:kenegozi,项目名称:NoRM,代码行数:11,代码来源:LinqTests.cs

示例11: AvgShouldReturn15WhenThreeProductsInDBWIthSumPrice60AndLessThan30

 public void AvgShouldReturn15WhenThreeProductsInDBWIthSumPrice60AndLessThan30()
 {
     using (var session = new Session())
     {
         session.Add(new TestProduct { Name = "1", Price = 10 });
         session.Add(new TestProduct { Name = "2", Price = 20 });
         session.Add(new TestProduct { Name = "3", Price = 30 });
         var result = session.Products.Where(x => x.Price < 30).Average(x => x.Price);
         Assert.Equal(15, result);
     }
 }
开发者ID:ereichert,项目名称:NoRM,代码行数:11,代码来源:LinqAggregates.cs

示例12: SupplierShouldBeQuerybleByAddress

 public void SupplierShouldBeQuerybleByAddress()
 {
     using (var session = new Session())
     {
         var add = new Address { State = "HI", Street = "100 Main" };
         session.Add(new TestProduct { Name = "Test3", Price = 10, Supplier = new Supplier { Name = "Steve", CreatedOn = new DateTime(2000, 2, 1), Address = add } });
         session.Add(new TestProduct { Name = "Test4", Price = 22, Supplier = new Supplier { Name = "Steve", CreatedOn = new DateTime(2001, 2, 1) } });
         session.Add(new TestProduct { Name = "Test5", Price = 33, Supplier = new Supplier { Name = "Steve", CreatedOn = new DateTime(2002, 2, 1) } });
         var products = session.Products.Where(x => x.Supplier.Address.State == "HI").ToList();
         Assert.Equal(1, products.Count);
     }
 }
开发者ID:ereichert,项目名称:NoRM,代码行数:12,代码来源:LinqDeepGraph.cs

示例13: OneProductShouldBeReturnedWhen3InDbWithFirst

 public void OneProductShouldBeReturnedWhen3InDbWithFirst()
 {
     using (var session = new Session())
     {
         session.CreateCappedCollection("Product"); //only capped collections return in insertion order
         session.Add(new Product {Name = "Test1", Price = 10});
         session.Add(new Product {Name = "Test2", Price = 22});
         session.Add(new Product {Name = "Test3", Price = 33});
         var result = session.Products.First();
         Assert.Equal("Test1", result.Name);
     }
 }
开发者ID:kenegozi,项目名称:NoRM,代码行数:12,代码来源:LinqTests.cs

示例14: One_Product_Should_Be_Returned_When_Nested_Supplier_Queried

        public void One_Product_Should_Be_Returned_When_Nested_Supplier_Queried()
        {
            var session = new Session();
            session.Drop<Product>();

            session.Add(new Product() { Name = "Test3", Price = 10, Supplier = new Supplier() { Name = "Steve" } });
            session.Add(new Product() { Name = "Test4", Price = 22 });
            session.Add(new Product() { Name = "Test5", Price = 33 });

            var products = session.Products.Where(x => x.Supplier.Name == "Steve").ToList();

            Assert.AreEqual(1, products.Count);
        }
开发者ID:sdether,项目名称:NoRM,代码行数:13,代码来源:LinqDeepGraph.cs

示例15: FourProductsShouldBeReturnedWhenStartsOrEndsWithX

 public void FourProductsShouldBeReturnedWhenStartsOrEndsWithX()
 {
     using (var session = new Session())
     {
         session.Add(new Product {Name = "Test3X", Price = 10});
         session.Add(new Product {Name = "Test4X", Price = 22});
         session.Add(new Product {Name = "Test5", Price = 33});
         session.Add(new Product {Name = "XTest3", Price = 10});
         session.Add(new Product {Name = "XTest4", Price = 22});
         var products = session.Products.Where(x => x.Name.StartsWith("X") || x.Name.EndsWith("X")).ToList();
         Assert.Equal(4, products.Count);
     }
 }
开发者ID:kenegozi,项目名称:NoRM,代码行数:13,代码来源:LinqTests.cs


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