任何人都可以證實這不能按預期工作,因爲我得到一個錯誤,它試圖訪問屬性,而不是嘗試訪問字段。FluentNHibernate - ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
private IList<MetaPackage> _metaPackages;
public virtual IEnumerable<MetaPackage> MetaPackages
{
get
{
return _metaPackages;
}
}
流利的映射
HasMany<MetaPackage>(x
=>x.MetaPackages).Table("dnnSphere_Package").KeyColumn("Id")
.Inverse().LazyLoad().Cascade.AllDeleteOrphan()
.Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
單元測試
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();
錯誤:
它拋出一個錯誤,它無法找到的屬性設置,即使它應該走線槽場,因爲它是隻讀屬性。
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.PersistenceSpecification
1.ListValue
1.SetValue(Ob ject target) in E:\Users\epitka\Documents\DEVELOPMENT\fluent- nhibernate\src\FluentNHibernate\Testing\PersistenceSpecification.cs: line 174
如果如果交換機策略使用ReadOnlyPropertyTrhoughPascalCaseField它正確地拋出這個錯誤:
NHibernate.PropertyNotFoundException: Could not find field '_MetaPackages' in class 'dnnSphere.Meta.Model.MetaProject'
如此看來,ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)不正確映射它的財產而不是到現場。