views:

146

answers:

4

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

A: 

You might be able to get the override to work if you add a private Get method to your property.

Tom Bushell
A: 

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"

Jason
Others have had trouble with private backing variables and FNH - I wouldn't use them unless I really, really needed them. I suggest you try declaring the property as "public virtual string Value { get; set; }" in order to get the override working, and then experiment with making the "get" private (I know you can make "set" private, but not sure about "get").
Tom Bushell
A: 

You can add public getter throwing NotSupportedException to make compiler happy:

public virtual string Value 
{ 
    get { throw new NotSupportedException(); }
    set { _value = value; }
}
Konstantin Spirin
A: 

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");
});
Brad Mellen-Crandell

related questions