Issue with one-to-one and PropertyReference

20 views
Skip to first unread message

codemonkey

unread,
Jun 21, 2012, 9:29:43 PM6/21/12
to nhu...@googlegroups.com
Why does it do this check in PropertyReference in the OneToOneMapper:

if (this._member != null && propertyInTheOtherSide.DeclaringType != this._member.GetPropertyOrFieldType())
            {
                throw new ArgumentOutOfRangeException("propertyInTheOtherSide"string.Format("Expected a member of {0} found the member {1} of {2}"this._member.GetPropertyOrFieldType(), propertyInTheOtherSide, propertyInTheOtherSide.DeclaringType));
            }

I have classes like so:

public class Owner {
    public Foo1 Foo1 {get;set;}
    public Foo2 Foo2 {get;set;}
}

public class Foo {
    public Owner Owner {get;set;}
}

public class Foo1 : Foo {
}

public class Foo2 : Foo {
}

I then have a mapping for Owner with a OneToOne like so:

OneToOne(x => x.Foo1, m =>
            {
                m.Cascade(Cascade.All);
                m.PropertyReference<Foo1>(x => x.Owner);
            });

This throws the exception, the only way I could get it to work is add an override for Owner to Foo1 and Foo2 like so and ignore the Owner property in the Foo1 and Foo2 mappings:

public class Foo1 {
    public Owner Owner {
        get { return base.Owner; }
        set { base.Owner = value; }
    }
}


Is there a better way to get around this *hack*?


Cheers

Reply all
Reply to author
Forward
0 new messages