I've had the same problem, except that NHibernate complained about a missing class.
I believe you can use the following convention to remove the part that maps the property from the class:
public class IgnorePropertiesClassMapConvention : IClassConvention
{
public bool Accept(IClassMap classMaps)
{
return true;
}
public void Apply(IClassMap classMap)
{
var partsToIgnore = classMap.Parts.OfType<IProperty>()
.Where(IgnoreProperty).ToList();
foreach (var part in partsToIgnore)
((IList<IMappingPart>)classMap.Parts).Remove(part);
}
private bool IgnoreProperty(IProperty property)
{
// Your logic would be here
}
}
The code I've used is a bit different, since what I needed to remove was a ManyToOne mapping:
public class IgnorePartsBasedOnReturnTypeClassMapConvention : IClassConvention
{
public bool Accept(IClassMap classMaps)
{
return true;
}
public void Apply(IClassMap classMap)
{
var partsToIgnore = classMap.Parts.OfType<IManyToOnePart>()
.Where(IgnorePart).ToList();
foreach (var part in partsToIgnore)
((IList<IMappingPart>)classMap.Parts).Remove(part);
}
private bool IgnorePart(IManyToOnePart part)
{
return IgnoreProperty(part.Property);
}
private bool IgnoreProperty(PropertyInfo propertyInfo)
{
var ignoredNamespaces = new []{"namespacesToIgnore"};
return ignoredNamespaces.Any(namespc => propertyInfo.GetGetMethod().ReturnType.Namespace.StartsWith(namespc));
}
}
I'm not exactly sure if this is the best way to do this.
My feeling is that the discoverability part should be overriden with the ability to not even build up the part for unwanted properties, but for now this seems to work.