本文整理汇总了C#中Category.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Category.Create方法的具体用法?C# Category.Create怎么用?C# Category.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
// Old way
// Hashtable properties = new Hashtable();
//
// properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
// properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
// properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
// properties.Add("hibernate.connection.connection_string",
// "Data Source=.;Initial Catalog=bookdb;Integrated Security=SSPI");
//
// InPlaceConfigurationSource source = new InPlaceConfigurationSource();
// source.Add(typeof(ActiveRecordBase), properties);
// New way
InPlaceConfigurationSource config = InPlaceConfigurationSource.BuildForMSSqlServer(".", "test");
ActiveRecordStarter.Initialize(config,
typeof(LineItem), typeof(Order),
typeof(Category), typeof(Product),
typeof(Customer));
// Framework started, let's create the schema
ActiveRecordStarter.CreateSchema();
// Now let's play
Customer invalid = new Customer();
invalid.Name = "john"; // Less than the minimum
invalid.Email = "someinvalidemail.com";
if (!invalid.IsValid())
{
foreach(String msg in invalid.ValidationErrorMessages)
{
Console.WriteLine(msg);
}
}
try
{
// This will fail
invalid.Create();
}
catch(Exception ex)
{
}
Order order;
Product product;
using(new SessionScope())
{
Category root = new Category("Petshot");
root.Create();
Category c1 = new Category("Dogs");
c1.Parent = root;
c1.Create();
product = new Product();
product.Name = "It";
product.Price = 10f;
product.Categories.Add(c1);
product.Create();
Customer customer = new Customer();
customer.Name = "another customer";
customer.Email = "[email protected]";
customer.Create();
order = new Order();
order.Customer = customer;
order.Total = 100f;
order.Create();
// Associate order and product (the hard way)
LineItem item = new LineItem(order, product);
item.Quantity = 10;
item.Create();
}
using(new SessionScope())
{
// Change just the association
LineItem item = LineItem.Find(order, product);
item.Quantity = 12;
}
}