NHibernate 3.2 - 现在所有属性都需要“设置”吗?方法?
我们最近将 Automapped FNH / NH 项目升级到 NH 3.2,但遇到了很多问题。
我们的对象模型中有很多属性只有一个“getter”,例如,
public virtual float Polydispersity
{
get { return MeasurementRun.PolyDispersity; }
}
这曾经工作正常,但现在我们收到“无法找到属性的setter”错误。
这很难找到,因为由于某种原因,自动映射无法自动创建数据库表,导致保存到数据库时出现“无持久化”错误 - 请参阅 此了解详情。
这是因为LinFu现在内置到NH了吗?我知道私人设置器不再起作用,这似乎是一个类似的问题。
我们曾经使用 Castle,我真的很喜欢 NH 现在不需要所有其他 DLL,但如果它破坏了我们对象模型的很大一部分,则不需要。
关于如何解决这个问题有什么建议吗?
堆栈跟踪
FluentNHibernate.Cfg.FluentConfigurationException:无效或 创建 SessionFactory 时使用了不完整的配置。 检查 PotentialReasons 集合和 InnerException 了解更多详细信息。
---> NHibernate.PropertyNotFoundException:找不到设置器 对于类中的“多分散性”属性 'BI_OverlordDlsAppCore.OfeDlsMeasurement' 位于 NHibernate.Properties.BasicPropertyAccessor.GetSetter(类型类型, 字符串 propertyName) 在 NHibernate.Mapping.Property.GetSetter(Type 克拉兹)在 NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildPropertySetter(属性 映射属性、持久类映射实体)位于 NHibernate.Tuple.Entity.AbstractEntityTuplizer..ctor(EntityMetamodel 实体元模型、持久类映射信息)位于 NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel 实体元模型、持久类映射实体)位于 NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass 映射实体、EntityMetamodel em) at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass 持久类,ISessionFactoryImplementor sessionFactory)在 NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistClass、ICacheConcurrencyStrategy 缓存、 ISessionFactoryImplementor 工厂)位于 NHibernate.Persister.Entity.JoinedSubclassEntityPersister..ctor(PersistentClass persistClass、ICacheConcurrencyStrategy 缓存、 ISessionFactoryImplementor工厂,IMapping映射)位于 NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass 模型、ICacheConcurrencyStrategy 缓存、ISessionFactoryImplementor 工厂,IMapping cfg)位于 NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping 映射、设置设置、EventListeners 侦听器)位于 NHibernate.Cfg.Configuration.BuildSessionFactory() 在 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() --- 内部异常堆栈跟踪结束 --- 位于 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 在 BI_OverlordPackageCore.OfeDatabase.CreateSqliteSessionFactory() 中 C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 映射 Bug\OfeDatabase.cs:第 192 行 BI_OverlordPackageCore.OfeDatabase.GetMainSession() 中 C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 映射 Bug\OfeDatabase.cs:第 147 行 BI_OverlordPackageCore.OfeDatabase.Initialize(Assembly[] 程序集) 在 C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 映射 Bug\OfeDatabase.cs:第 305 行 FNH_1._3_Mapping_Bug.Form1.button1_Click(对象发送者,EventArgs e) 在 C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 映射 Bug\Form1.cs:第 23 行位于 System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&m, MouseButtons 按钮,Int32 单击)位于 System.Windows.Forms.Control.WndProc(Message&m) at System.Windows.Forms.ButtonBase.WndProc(Message&m) at System.Windows.Forms.Button.WndProc(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg、IntPtr wparam、IntPtr lparam)
We recently upgraded our Automapped FNH / NH project to NH 3.2, and are running into a lot of problems.
We have a lot of properties in our object model that only have a "getter", e.g.
public virtual float Polydispersity
{
get { return MeasurementRun.PolyDispersity; }
}
This used to work fine, but now we get "Could not find a setter for property" errors.
This was hard to find, because for some reason the automapping was silently failing to create the DB tables, leading to "no persister" errors when saving to the DB - see this for details.
Is this because LinFu is now built into NH? I know private setters no longer work, and this seems to be a similar problem.
We used to use Castle, and I really like that NH doesn't require all those other DLLs now, but not if it breaks a big part of our object model.
Any suggestions on how to get around this?
Stack Trace
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or
incomplete configuration was used while creating a SessionFactory.
Check PotentialReasons collection, and InnerException for more detail.---> NHibernate.PropertyNotFoundException: Could not find a setter
for property 'Polydispersity' in class
'BI_OverlordDlsAppCore.OfeDlsMeasurement' at
NHibernate.Properties.BasicPropertyAccessor.GetSetter(Type type,
String propertyName) at NHibernate.Mapping.Property.GetSetter(Type
clazz) at
NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildPropertySetter(Property
mappedProperty, PersistentClass mappedEntity) at
NHibernate.Tuple.Entity.AbstractEntityTuplizer..ctor(EntityMetamodel
entityMetamodel, PersistentClass mappingInfo) at
NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel
entityMetamodel, PersistentClass mappedEntity) at
NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass
mappedEntity, EntityMetamodel em) at
NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass
persistentClass, ISessionFactoryImplementor sessionFactory) at
NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass
persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory) at
NHibernate.Persister.Entity.JoinedSubclassEntityPersister..ctor(PersistentClass
persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping) at
NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass
model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor
factory, IMapping cfg) at
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping
mapping, Settings settings, EventListeners listeners) at
NHibernate.Cfg.Configuration.BuildSessionFactory() at
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() ---
End of inner exception stack trace --- at
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() at
BI_OverlordPackageCore.OfeDatabase.CreateSqliteSessionFactory() in
C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 Mapping
Bug\OfeDatabase.cs:line 192 at
BI_OverlordPackageCore.OfeDatabase.GetMainSession() in
C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 Mapping
Bug\OfeDatabase.cs:line 147 at
BI_OverlordPackageCore.OfeDatabase.Initialize(Assembly[] assemblies)
in C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 Mapping
Bug\OfeDatabase.cs:line 305 at
FNH_1._3_Mapping_Bug.Form1.button1_Click(Object sender, EventArgs e)
in C:\Bicw_Dev\Bic.Net\Private Projects\NHibernate\FNH 1.3 Mapping
Bug\Form1.cs:line 23 at
System.Windows.Forms.Control.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks) at
System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.ButtonBase.WndProc(Message& m) at
System.Windows.Forms.Button.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该映射只读属性。
- 解决方案 1
- 解决方案 2
...然后使用您的conf:
编辑:添加了 Tom Bushell 的建议
You should not map readonly properties.
- Solution 1
- Solution 2
... Then use your conf :
Edit : Added Tom Bushell's suggestion