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