Just an observation,

List<Division> ancestors;
public virtual IList<Division> Ancestors
{
        get
        {
                ancestors = ancestors ?? GetAncestors(this);
                return ancestors;
        }

}

This kind of properties will always be mapped with the current version
of FNH, because of the implementation of the
ManyToManyAutoMapper (look end of post).

MapsProperty of this class will map all properties for which
GetInverseProperty is not null.

GetInverseProperty will always return true for the following case

class A
{
  IList<B> Bs { get {...}}
}

class B
{
  IList<A> As {get {...}
}

which defines many to many relationship between this two classes.
In its current implementation it will also return true if A and B are
equal.

This means that for every property that returns IList<A> that is a
member of class A this mapping will be used,
it doesn't matter if this property is read only.
I think this is not desired and shall be fixed, by comparing if the
two classes are the same.


Current implementation of ManyToManyAutoMapper:

public bool MapsProperty(PropertyInfo property)
        {
            var type = property.PropertyType;
            if (type.Namespace != "Iesi.Collections.Generic" &&
                type.Namespace != "System.Collections.Generic")
                return false;

            var hasInverse = GetInverseProperty(property) != null;
            return hasInverse;
        }

        private PropertyInfo GetInverseProperty(PropertyInfo property)
        {
            Type type = property.PropertyType;
            var inverseSide = type.GetGenericTypeDefinition()
                .MakeGenericType(property.DeclaringType);

            var argument = type.GetGenericArguments()[0];
            return argument.GetProperties()
                .Where(x => x.PropertyType == inverseSide)
                .FirstOrDefault();
        }



On Mar 18, 6:12 pm, "wgp...@gmail.com" <wgp...@gmail.com> wrote:
> Example:
>
> I have a helper property defined as such, that for a particular
> Division object, will return a collection of all its ancestors based
> on a parent/child relationship in the db:
>
> List<Division> ancestors;
> public virtual IList<Division> Ancestors
> {
>         get
>         {
>                 ancestors = ancestors ?? GetAncestors(this);
>                 return ancestors;
>         }
>
> }
>
> But I get this exception using AutoPersistence:
>
> NHibernate.MappingException: Repeated column in mapping for
> collection: TrainingDB.Core.Division.Ancestors column: DivisionID
>
> My question:  Why is it even looking at the Ancestors property? And is
> there a way to tell it not too?
--~--~---------~--~----~------------~-------~--~----~
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