Создал cs -ки и мапинги при помощи MyGeneration
Привожу один пример что получилось(всё делал как в примере http://vadim-kup.livejournal.com/2540.html):
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
/*
using MyGeneration/Template/NHibernate (c) by lujan99@usa.net
*/
using System;
using System.Collections;
using System.Collections.Generic;
namespace nhNamespace
{
/// <summary>
/// Country object for NHibernate mapped table 'Country'.
/// </summary>
[Serializable]
public class Country
{
#region Member Variables
protected int _id;
protected string _countryname;
protected IList<Address> _address;
protected IList<City> _city;
#endregion
#region Constructors
public Country() {}
public Country(string countryname)
{
this._countryname= countryname;
}
#endregion
#region Public Properties
public virtual int Id
{
get { return _id; }
set {_id= value; }
}
public virtual string CountryName
{
get { return _countryname; }
set {_countryname= value; }
}
public virtual IList<Address> Address
{
get { return _address; }
set {_address= value; }
}
public virtual IList<City> City
{
get { return _city; }
set {_city= value; }
}
#endregion
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value members
/// </summary>
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
Country castObj = (Country)obj;
return ( castObj != null ) &&
this._id == castObj.Id;
}
/// <summary>
/// local implementation of GetHashCode based on unique value members
/// </summary>
public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * _id.GetHashCode();
return hash;
}
#endregion
}
}
и
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!--Build: with lujan99@usa.net Nhibernate template-->
<class name="nhNamespace.Country,nhAssembly" table="Country" lazy="true">
<id name="Id" column="Id" type="int">
<generator class="native" />
</id>
<property name="CountryName" column="CountryName" type="string" not-null="true" />
<bag name="Address" inverse="true" lazy="true" cascade="delete">
<key column="CountryId" />
<one-to-many class="nhNamespace.Address,nhAssembly" />
</bag>
<bag name="City" inverse="true" lazy="true" cascade="delete">
<key column="CountryId" />
<one-to-many class="nhNamespace.City,nhAssembly" />
</bag>
</class>
</hibernate-mapping>
После добавил конфигурационный файл App.config и вписал внего следующие
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add key="hibernate.show_sql" value="true" />
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string" value="Data Source=kn002\sqlexpress;Initial Catalog=Diplom;Integrated Security=True" />
</nhibernate>
</configuration>
Запускаю и он мне выдаёт ошибку .. Что я не то делаю...