本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}