本文整理汇总了C#中Customer.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# Customer.IsValid方法的具体用法?C# Customer.IsValid怎么用?C# Customer.IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer.IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(Customer entity)
{
if(entity.IsValid())
{
CustomerRepo.Save(entity);
}
}
示例2: 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;
}
}