jagregory/fluent-nhibernate — Issue #109: IgnoreProperty does not ignore overridden properties in sub-classes
Author: chilversc
Created: 2011-11-11 17:29:40+00:00
State: open

`mapping.IgnoreProperty (x => x.IsOverriden)` does not ignore properties that are overriden in sub-classes.
Further more, it cannot ignore properties that are overriden in sub-classes.

Eg

```csharp
public class ItemBase { public virtual bool IsOverriden { get { return false; } } }
public class Item : ItemBase { public override bool IsOverriden { get { return true; } } }
```

This partially works, it will ignore `ItemBase.IsOverriden` but not `Item.IsOverriden`

```csharp
public void Override (AutoMapping mapping) {
mapping.IgnoreProperty (x => x.IsOverriden);
}
```

This does *not* work, Item.IsOverriden will not be ignored.

```csharp
public void Override (AutoMapping
mapping) {
// This does not work, it will not ignore Item.IsOverriden
mapping.IgnoreProperty (x => x.IsOverriden);
}
```

As a work around the following does work:

```csharp
public void Override (AutoMapping
mapping) {
mapping.IgnoreProperty (Reveal.Member
("IsOverriden"));
}
```

----

The following example reproduces the error with FNH 1.3.0.717 and earlier: https://gist.github.com/1358583

```csharp
// uses NHibernate 3.2.0.4000
// uses FluentNHibernate 1.3.0.717

namespace ConsoleApplication1
{
using System;
using System.IO;
using FluentNHibernate;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;

public class Program
{
public static void Main()
{
var cfg = new AutoMappingConfiguration ();
var mapping = AutoMap
.AssemblyOf (cfg)
.UseOverridesFromAssemblyOf ()
.Conventions.AddFromAssemblyOf ();

using (var file = File.CreateText ("mapping.xml"))
Fluently.Configure ()
.Database (SQLiteConfiguration.Standard.InMemory)
.ProxyFactoryFactory ()
.Mappings (m => m.AutoMappings.Add (mapping).ExportTo (file))
.BuildConfiguration ();
}
}

public class AutoMappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type)
{
return type == typeof (ItemBase) || type == typeof (Item);
}
}

public class ItemBaseOverride : IAutoMappingOverride
{
public void Override (AutoMapping mapping)
{
mapping.IgnoreProperty (x => x.IsOverriden);
}
}

public class ItemOverride : IAutoMappingOverride

{
public void Override (AutoMapping
mapping)
{
// Fails:
mapping.IgnoreProperty (x => x.IsOverriden);

// Works:
//mapping.IgnoreProperty (Reveal.Member
("IsOverriden"));
}
}

public class ItemBase
{
public long Id { get; set; }
public string Name { get; set; }

public virtual bool IsOverriden
{
get { return false; }
}
}

public class Item : ItemBase
{
public override bool IsOverriden
{
get { return true; }
}
}
}
```

Example Result (cleaned up a little)

```xml

```