Access strategy for components

Original Post TigerShark's Avatar

TigerShark

13 May, 2010 07:16 PM via web

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...

  1. Support Staff 2 Posted by James Gregory on 16 May, 2010 04:44 PM

    James Gregory's Avatar

    Was this the question that you got answered on the mailing list?

  2. 3 Posted by Kenneth Siewers Møller on 16 May, 2010 05:16 PM

    Kenneth Siewers Møller's Avatar

    Yes it was...
    I guess I should vote for more descriptive error messages in
    NHibernate... :)

    Kenneth

  3. James Gregory resolved this discussion on 16 May, 2010 05:28 PM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

05 Jul, 2010 10:29 PM
05 Jul, 2010 12:45 PM
05 Jul, 2010 12:42 PM
05 Jul, 2010 12:17 PM
05 Jul, 2010 12:12 PM

 

03 Jul, 2010 12:26 AM
02 Jul, 2010 02:17 PM
02 Jul, 2010 08:18 AM
02 Jul, 2010 12:20 AM
01 Jul, 2010 10:14 PM