Ok!
Sorry, I thought that problem/Exception might be a well known one! ;)
The place where I initialise NHibernate:
Code:
public void InializeNHibernate()
{
try
{
Configuration objConfiguration = new Configuration();
objConfiguration.Configure();
_objFactory = objConfiguration.BuildSessionFactory();
_bNHibernateInitialized = true;
}
catch (Exception ex)
{
_objLogger.Warn("Error when initializing NHibernate : " + ex);
}
}
2 typical classes:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Mapping.Attributes;
namespace ....Persistence
{
[Class(Table = "assetgroups")]
public class AssetGroup
{
#region Fields
private int _iAssetGroupId;
private Client _objAssetGroupClient;
private string _strAssetGroupName;
private List<Asset> _collAssets = new List<Asset>();
private List<User> _collUsers = new List<User>();
#endregion
#region Properties
[Id(Name = "assetGroupId")]
[Generator(1, Class = "native")]
public int AssetGroupId
{
get { return _iAssetGroupId; }
set { _iAssetGroupId = value; }
}
[ManyToOne(Column = "assetGroupClientId")]
public Client AssetGroupClient
{
get { return _objAssetGroupClient; }
set { _objAssetGroupClient = value; }
}
[Property(Column = "assetGroupName")]
public string AssetGroupName
{
get { return _strAssetGroupName; }
set { _strAssetGroupName = value; }
}
[Bag(1, Inverse = true, Lazy = true, Table = "assetGroupAssets", Cascade = CascadeStyle.SaveUpdate),
Key(2, Column = "[assetGroupAssetGroupId]"),
ManyToMany(3, Column = "[assetGroupAssetAssetId]", ClassType = typeof(Asset))]
public virtual List<Asset> Assets
{
get
{
return _collAssets;
}
set
{
_collAssets = value;
}
}
[Bag(1, Inverse = true, Lazy = true, Table = "assetGroupPerms", Cascade = CascadeStyle.SaveUpdate),
Key(2, Column = "[assetGroupPermGroupId]"),
ManyToMany(3, Column = "[assetGroupPermUserId]", ClassType = typeof(User))]
public virtual List<User> Users
{
get
{
return _collUsers;
}
set
{
_collUsers = value;
}
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Mapping.Attributes;
namespace ....Persistence
{
[Class(Table = "clients")]
public class Client
{
#region Fields
private int _iClientId;
private string _strClientName;
private string _strClientHouseNameNumber;
private string _strClientStreetName;
private string _strClientTown;
private string _strClientCity;
private string _strClientCounty;
private string _strClientPostcode;
private string _strClientCountry;
#endregion
#region Properties
[Id(Name = "clientId")]
[Generator(1, Class = "native")]
public int ClientId
{
get { return _iClientId; }
set { _iClientId = value; }
}
[Property(Column = "clientName")]
public string ClientName
{
get { return _strClientName; }
set { _strClientName = value; }
}
[Property(Column = "clientHouseNameNumber")]
public string ClientHouseNameNumber
{
get { return _strClientHouseNameNumber; }
set { _strClientHouseNameNumber = value; }
}
[Property(Column = "clientStreetName")]
public string ClientStreetName
{
get { return _strClientStreetName; }
set { _strClientStreetName = value; }
}
[Property(Column = "clientTown")]
public string ClientTown
{
get { return _strClientTown; }
set { _strClientTown = value; }
}
[Property(Column = "clientCity")]
public string ClientCity
{
get { return _strClientCity; }
set { _strClientCity = value; }
}
[Property(Column = "clientCounty")]
public string ClientCounty
{
get { return _strClientCounty; }
set { _strClientCounty = value; }
}
[Property(Column = "clientPostcode")]
public string ClientPostcode
{
get { return _strClientPostcode; }
set { _strClientPostcode = value; }
}
[Property(Column = "clientCountry")]
public string ClientCountry
{
get { return _strClientCountry; }
set { _strClientCountry = value; }
}
#endregion
}
}
If you need anything else let me know.
Regards, Jean