Hi nHibernate Heroes ;)
I have to ask you about it since I think/google about it for some time
and still have no consistent answer.
My problem is in fluent mapping collections.
What I need is custom collection with proper business rule handling on
Add/Remove etc.What I don't want is inheriting/implementing
nHibernate's UserCollectionType which makes my business classes
attached to NH.
As far as I know there are two clean ways of doing it:
1. Use component mapping with some magic mapping inside. This way has
disadvantage of adding component name in the query - I'd have to use
Class.Component.Collection instead of Class.Collection which is much
more natural and elegant for me.
2. Create wrapper and attach it to regular Bag or whatever NH wants to
persist. The only problem of having wrapper I have found so far is it
is not mappable using Fluent NHibernate (or at least in its original
version), since it needs to operate on fields. Well it could operate
on properties, but I don't like to show bare internal collection to
the world.

So - my question is - Is there third method of having custom
collection? Did I missed something? What is the proper way of doing
it?
My solution was modifying ClassMap<T> and adding another HasMany
override as following:
        public OneToManyPart<TChild> HasMany<TChild>(string fieldName)
{
          FieldInfo fInfo = typeof(T).GetField
(fieldName,BindingFlags.NonPublic|BindingFlags.Instance);
          if (fInfo == null) {
            throw new FieldNotFoundException(fieldName);
          }
          PropertyInfo pi = new FakePropertyInfo(fInfo);
          return HasMany<TChild>(pi).Access.AsField();
        }
Simple, easy and clean for me. And - what's most important - makes my
collection wrapper working as expected.
I can send full implementation patch if anyone is interested.
Best regards
H.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to