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


C# LineItem.Create方法代码示例

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


在下文中一共展示了LineItem.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;
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:90,代码来源:App.cs


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