views:

172

answers:

1

Can anybody confirm that this does not work as expected, as I am getting an error that it is trying to access property rather then trying to access field.

private IList<MetaPackage> _metaPackages;
public virtual IEnumerable<MetaPackage> MetaPackages
{
 get
 {
    return _metaPackages;
 }
}

Fluent mapping

    HasMany<MetaPackage>(x 
=>x.MetaPackages).Table("dnnSphere_Package").KeyColumn("Id")
 .Inverse().LazyLoad().Cascade.AllDeleteOrphan()               
.Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)

Unit Test

new PersistenceSpecification<MetaProject>(Session)
                .CheckProperty(x => x.Name, "Test")
                .CheckProperty(x => x.Description, "Description")
                .CheckList(x=>x.MetaPackages, new List<MetaPackage> { new 
MetaPackage ("name")})
                .VerifyTheMappings();

Error:

It throws an error that it cannot find Property setter, even though it should go trough a field, as it is readonly property.

System.ArgumentException: Property set method not found. at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at FluentNHibernate.Testing.PersistenceSpecification1.ListValue1.SetValue(Ob ject target) in E:\Users\epitka\Documents\DEVELOPMENT\fluent- nhibernate\src\FluentNHibernate\Testing\PersistenceSpecification.cs: line 174

If if switch strategy to use ReadOnlyPropertyTrhoughPascalCaseField it correctly throws this error:

NHibernate.PropertyNotFoundException: Could not find field '_MetaPackages' in class 'dnnSphere.Meta.Model.MetaProject'

So it seems that ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore) is mapping it incorrectly to property rather then to a field.

A: 

Ok, "problem" is (if it can be called problem) in PersistenceSpecification. It works with PropertyInfo, no matter how it is mapped and requires setter on property. Not ideal, but one can create private setter to be able to test with PersistenceSpecification.

epitka