Hi, I'm struggling with the default behavior of mappings by code that do 
map property of parent if it is mapped in inherited class. The problem is 
following:

This test fails:

public class InheritedPropertyMappingTests
{
private class Foo
{
public virtual int Id { get; set; }

public virtual string ShouldNotBeMapped
{
get { return ""; }
set { throw new NotSupportedException();}
}
}

private class Bar : Foo
{
public override string ShouldNotBeMapped { get; set; }
}

[Test]
public void 
WhenPropertyIsNotMapped_ItShouldNotBePresentInResultingMappings()
{
var mapper = new ModelMapper(new SimpleModelInspector());
mapper.Class<Foo>(map => { });
mapper.Subclass<Bar>(map => map.Property(x => x.ShouldNotBeMapped));

var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

var hbmClass = hbmMapping.RootClasses[0];
 Assert.That(hbmClass.Name, Is.StringContaining("Foo"));
Assert.That(hbmClass.Properties.Where(x => x.Name == "ShouldNotBeMapped"), 
Is.Empty, "Property is mapped only in inherited class, it should not be 
mapped in base class");
}
}

It fails as intended by test WhenMapPropertiesInTheInheritedThenMapInBase. 
Comment there says that it can be overridden with he help of 
SimpleModelInspector and examining ReflectedType and DeclaringType. But 
when I try to add my custom Inspector:

private class MyInspector : SimpleModelInspector
{
protected override bool 
DeclaredPolymorphicMatch(System.Reflection.MemberInfo member, 
Func<System.Reflection.MemberInfo, bool> declaredMatch)
{
return base.DeclaredPolymorphicMatch(member, declaredMatch);
}
}

then both member.ReflectedType and member.DeclaringType are equal to Foo. 
How do I map property only in inherited class? It wan't even an issue with 
XML mappings.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to