I’m trying to find out how to programmatically (i.e. without using the FieldAttribute) add an index column for NHibernate Search (Lucene.net).
I’m having inheritance issues due to the fact that the FieldAttribute is not automatically inherited.
The following code illustrates what I want to do.
class A
{
[Field(Index.Tokenized)]
public virtual string P1
{
get
{
return "P1";
}
}
}
class B : A
{
public override string P1
{
get
{
return "P1+";
}
}
}
I expected the override of P1 to be indexed but it didn’t. When I inspected the FieldAttribute class, I found that it didn’t have Inherited = true specified in the AttributeUsage attribute.
I then added a FieldAttribute to the overridden property but that resulted in NHibernate Search bailing out with an exception stating that an item with the same key has already been added to a dictionary. I figure that’s because there’s two equally named properties both with a FieldAttribute on them in the type chain and it accepts only one.
So, how do I programmatically solve this by not using FieldAttribute?
Non-attribute mapping was recently implemented, take a look at this blog post.