我有一個很大的問題!在nhibernate中映射具有多個聯合子類的抽象類時,我不斷收到異常。 當我只使用一個聯合子類時,我沒有得到任何錯誤,一切正常。當我使用多個子類此錯誤occures:對象與目標類型不匹配發生異常getter
[TargetException:對象不匹配目標類型] System.Reflection.RuntimeMethodInfo.CheckConsistency(目標對象)10909543 System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(對象obj,BindingFlags invokeAttr,Binder binder,Object []參數,CultureInfo culture)+11 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []參數,CultureInfo culture)+54 System.Reflection .RuntimePropertyInfo.GetValue(對象OBJ,的BindingFlags invokeAttr,粘結劑粘結劑,對象[]索引,CultureInfo的培養)61 System.Reflection.RuntimePropertyIn fo.GetValue(對象OBJ,對象[]索引)19 NHibernate.Properties.BasicGetter.Get(目標對象)99
[的PropertyAccessException:異常發生MedControlWeb.Models.Logs.Log.Code的吸氣劑] NHibernate.Properties.BasicGetter.Get(目標對象)183 NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(字符串unsavedValue,IGetter identifierGetter,ITYPE identifierType,ConstructorInfo構造函數)160 NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(對PersistentClass mappedEntity,IIdentifierGenerator發生器)200 NHibernate.Tuple.Entity.EntityMetamodel..ctor(對PersistentClass對PersistentClass,ISessionFactoryImplementor的sessionFactory)775 NHiber nate.Persister.Entity.AbstractEntityPersister..ctor(對PersistentClass對PersistentClass,ICacheConcurrencyStrategy緩存,ISessionFactoryImplementor工廠)835 NHibernate.Persister.Entity.UnionSubclassEntityPersister..ctor(對PersistentClass對PersistentClass,ICacheConcurrencyStrategy緩存,ISessionFactoryImplementor工廠,IMapping映射)220 NHibernate的.Persister.PersisterFactory.CreateClassPersister(PersistentClass模型,ICacheConcurrencyStrategy緩存,ISessionFactoryImplementor工廠,IMapping cfg)+369 NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping映射,設置設置,EventListeners監聽器)+2199 NHibernate.Cfg。 Configuration.BuildSessionFactory()+181
我的HBM文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MedControlWeb"
namespace="MedControlWeb.Models.Logs">
<class name="Log" abstract="true" lazy="false">
<id name="Code" column="code">
<generator class="hilo"/>
</id>
<property name="Description" column="description"/>
<property name="User" column="user"/>
<property name="Timestamp" column="timestamp"/>
<property name="Action" column="action"/>
<union-subclass name="SettingsLog" table="settings_log" lazy="false">
</union-subclass>
<union-subclass name="JobLog" table="job_log" lazy="false">
</union-subclass>
</class>
</hibernate-mapping>
我的抽象超類:
public class Log
{
public int Code { get; set; }
public DateTime Timestamp { get; set; }
public MedControlWeb.Enums.Action Action { get; set; }
public string Description { get; set; }
public int User { get; set; }
}
一個子類:
public class SettingsLog : Log
{
}
我要去哪裏錯了?
編輯: 我能做些什麼來解決這個問題?我沒有看到我可以修復它,因爲我有適當的get方法?
這個例外似乎很清楚。你有什麼特別的困難?如果你真的需要幫助,你應該發佈一個更好的代碼示例。請參閱http://stackoverflow.com/help/mcve – 2014-11-05 20:29:17
感謝您的回覆!很抱歉,我編輯了這個問題。我沒有看到我應該怎樣更好地吸氣。我希望你會? – 2014-11-05 21:11:43