gpt4 book ai didi

NHibernate 3.2 - 现在所有属性都需要 "set"方法吗?

转载 作者:行者123 更新时间:2023-12-03 16:42:08 25 4
gpt4 key购买 nike

我们最近将 Automapped FNH/NH 项目升级到 NH 3.2,但遇到了很多问题。

我们的对象模型中有很多只有“getter”的属性,例如

    public virtual float Polydispersity
{
get { return MeasurementRun.PolyDispersity; }
}

这以前可以正常工作,但现在我们得到“找不到属性的 setter ”错误。

这很难找到,因为由于某种原因自动映射无法创建数据库表,导致保存到数据库时出现“无持久性”错误 - 请参阅 this详情。

这是因为LinFu 现在内置在NH 中了吗?我知道私有(private)二传手不再工作,这似乎是一个类似的问题。

我们曾经使用 CaSTLe,我真的很喜欢 NH 现在不需要所有其他 DLL,但如果它破坏了我们对象模型的很大一部分,则不需要。

关于如何解决这个问题的任何建议?

堆栈跟踪

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)

最佳答案

您不应该映射只读属性。

- 解决方案 1

    var map = AutoMap.AssemblyOf<Dummy>()
.OverrideAll(x => x.IgnoreProperties(property => !property.CanWrite));

- 解决方案 2
internal class MyMappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return base.ShouldMap(member) && member.CanWrite;
}
}

...然后使用您的 conf :
var map = AutoMap.AssemblyOf<Dummy>(new MyMappingConfiguration());

编辑:添加了 Tom Bushell 的建议

关于NHibernate 3.2 - 现在所有属性都需要 "set"方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8101316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com