My domain objects support custom fields that are stored in such a way that requires metadata and logic to be applied before their values can be stored and retrieved.
I already have a Custom Field Repository that handles the persistence of custom fields, and I don't want to try to recreate that logic in NHibernate mappings.
I would however like to support lazy loading of my custom fields. It would be nice if I could somehow trick the proxy into calling my dedicated repository for loading and saving rather than going through the NHibernate engine.
One way I solved this problem was to implement an interceptor which worked, but I took a performance hit when loading large amounts of data, because the dedicated repository was called each time an entity was loaded. It would be nice instead, if those calls to load custom fields were done lazily! From what I understand lazy loading cannot be done in an interceptor.
I have looked into implementing a custom user type (IUserType and IUserCollectionType), but the documentation is very limited, and I want to learn if it is even possible to do what I want before I go down the path of trying.
Here is an example of one of my domain objects:
public class ContactEntity : ICustomFieldContainer
{
public long ContactId { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
#region ICustomFieldContainer Members
public List<CustomFieldEntity> CustomFields { get; set; }
#endregion
}