1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace MoreComplexSample
18 using Castle
.ActiveRecord
;
19 using Castle
.ActiveRecord
.Framework
.Config
;
23 public static void Main()
26 // Hashtable properties = new Hashtable();
28 // properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
29 // properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
30 // properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
31 // properties.Add("hibernate.connection.connection_string",
32 // "Data Source=.;Initial Catalog=bookdb;Integrated Security=SSPI");
34 // InPlaceConfigurationSource source = new InPlaceConfigurationSource();
35 // source.Add(typeof(ActiveRecordBase), properties);
38 InPlaceConfigurationSource config
= InPlaceConfigurationSource
.BuildForMSSqlServer(".", "test");
40 ActiveRecordStarter
.Initialize(config
,
41 typeof(LineItem
), typeof(Order
),
42 typeof(Category
), typeof(Product
),
45 // Framework started, let's create the schema
47 ActiveRecordStarter
.CreateSchema();
51 Customer invalid
= new Customer();
52 invalid
.Name
= "john"; // Less than the minimum
53 invalid
.Email
= "someinvalidemail.com";
55 if (!invalid
.IsValid())
57 foreach(String msg
in invalid
.ValidationErrorMessages
)
59 Console
.WriteLine(msg
);
75 using(new SessionScope())
77 Category root
= new Category("Petshot");
80 Category c1
= new Category("Dogs");
84 product
= new Product();
87 product
.Categories
.Add(c1
);
90 Customer customer
= new Customer();
91 customer
.Name
= "another customer";
92 customer
.Email
= "foo@bar.com";
96 order
.Customer
= customer
;
100 // Associate order and product (the hard way)
101 LineItem item
= new LineItem(order
, product
);
106 using(new SessionScope())
108 // Change just the association
109 LineItem item
= LineItem
.Find(order
, product
);