Hi,
using NHib 1.1 with VS 2005.
I wanted to use .NET 2.0 generics in my entity classes so consider the following example class:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" table="Application">
<id name="Id" column="ApplicationId" type="System.Int32" unsaved-value="-1" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>
<version name="Version" unsaved-value="undefined"/>
<property name="ModifiedTime" column="ModifiedTime" type="NHibernate.Nullables2.NullableDateTimeType, NHibernate.Nullables2"/>
<property name="CreatedTime" column="CreatedTime" type="NHibernate.Nullables2.NullableDateTimeType, NHibernate.Nullables2"/>
<property name="CreatedUser" column="CreatedUser" />
<property name="ModifiedUser" column="ModifiedUser" />
<property name="Name" column="Name" />
<property name="PasswordExpirationPeriod" column="PasswordExpirationPeriod" />
<property name="UserSessionExpirationPeriod" column="UserSessionExpirationPeriod" />
<property name="License" column="License" access="nosetter.camelcase-underscore"/>
<bag name="Menu" cascade="all" access="field.camelcase-underscore"
lazy="true" inverse="true" order-by="`Index`" >
<key column="ApplicationId" />
<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogMenuEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>
<bag name="_roles" cascade="all-delete-orphan" access="field.camelcase-underscore"
lazy="true" inverse="true" >
<key column="ApplicationId" />
<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogRoleEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>
</class>
</hibernate-mapping>
public class CatalogApplicationEntity
{
private IList _roles;
private IList<RoleEntity> _genericRoles;
public IList<RoleEntity> Roles
{
get
{
EntityCollection<RoleEntity> roles = _genericRoles as EntityCollection<RoleEntity>;
if ((_roles != null) && ((roles == null) || roles.InnerList != _roles))
{
roles = new EntityCollection<CatalogRoleEntity>(_roles);
}
return roles;
}
}
}
EntityCollection<T> is just a wrapper around a plain IList which simply routes calls to IList methods (planning to possibly implement IBindingList so its usage could get more advantageous than just allowing generic access).
This seems to be a good solution for my needs, except of a problem with using NHibernateUtil.Initialize to initialize the collection in the business tier for use in the UI client tier, because that method does not use the
access="field.camelcase-underscore" mapping file provided access naming strategy for the collection association:
public static void Initialize( object proxy )
{
if( proxy == null )
{
return;
}
else if( proxy is INHibernateProxy )
{
NHibernateProxyHelper.GetLazyInitializer( ( INHibernateProxy ) proxy ).Initialize();
}
else if( proxy is PersistentCollection )
{
( ( PersistentCollection ) proxy ).ForceInitialization();
}
}
Am I wrong thinking that NHibernateUtil.Initialize should consider access strategy when accessing its "proxy" parameter?
Regards,
Bartol
|