Access strategy for components
I'm facing a strange problem.
I have a class with a nested component containing two properties.
My default access strategy is backing field, but for the component, I'd like to use camelcase field. When I try to set the access strategy explicitly for the component, I get an error telling me that the backing field for the property, couldn't be found.
Is this a bug?
I can override the access strategy for properties on my normal class maps, but not on components.
Example mapping:
public sealed class FooMap : ClassMap<Foo>
{
public FooMap()
{
Table("foo");
Id(x => x.Id, "id")
.Access.CamelCaseField(Prefix.Underscore); // <- Works
Component(x => x.Bar, b =>
{
b.Map(x => x.Property1, "col1")
.Access.CamelCaseField(Prefix.Underscore); // <- Fails
b.Map(x => x.Property2, "col2")
.Access.CamelCaseField(Prefix.Underscore); // <- Fails
});
}
}
Class definitions:
public class Foo
{
private int _id;
public virtual int Id
{
get { return _id; }
}
public virtual Bar Bar { get; set; }
}
public class Bar
{
private string _property1;
private string _property2;
public virtual string Property1
{
get { return _property1; }
}
public virtual string Property2
{
get { return _property2; }
}
}
If I change the class properties to automatic, and keep the custom access, I get an error telling me that the manual backingfields for the properties are missing ("property1" and "property2").
I have no idea what I'm doing wrong here...
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by James Gregory on 16 May, 2010 04:44 PM
Was this the question that you got answered on the mailing list?
3 Posted by Kenneth Siewers Møller on 16 May, 2010 05:16 PM
Yes it was...
I guess I should vote for more descriptive error messages in
NHibernate... :)
Kenneth
James Gregory resolved this discussion on 16 May, 2010 05:28 PM.