How can I ignore properties of a component using Fluent Nhibernate's AutoPersistenceModel?
I am using Fluent NHibernate AutoMappings to map my entities, including a few component objects. One of the component objects includes a property like the following:
public string Value
{
set _value = value;
}
This causes an NHibernate.PropertyNotFoundException: "Could not find a getter for property 'Value'..."
I want to ignore this property.
I tried creating an IAutoMappingOverride for the component class but I couldn't use AutoMapping<>.IgnoreProperty(x => x.Value) for the same reason. "The property or indexer 'MyComponent.Value' cannot be used开发者_运维知识库 in this context because it lacks the get accessor"
I've also looked at IComponentConvention but can't see anyway of altering the mappings with this convention.
Any help would be appreciated...
Thanks
You can use:
Reveal.Member<Owner, object> ("Value")`.
Eg
mapping.IgnoreProperty(Reveal.Member<Owner, object> ("Value")
Reveal.Member can be used anywhere Fluent NHibernate expects an expression. This can be used to expose private/protected properties and fields.
You can use OverrideAll() in your mapping file. If you don't know the type that it will be a member of, then you need to use this version specify the member as a string. Here's the example from the Fluent Nhibernate Wiki.
.OverrideAll(map =>
{
map.IgnoreProperty("YourProperty");
});
You might be able to get the override to work if you add a private Get method to your property.
I've tried both a private and protected get accessor but the override won't compile unless the accessor is public.
"The property or indexer cannot be used in this context because it lacks the get accessor"
You can add public getter throwing NotSupportedException
to make compiler happy:
public virtual string Value
{
get { throw new NotSupportedException(); }
set { _value = value; }
}
精彩评论