我最近將Windows SmartClient解決方案從nHibernate 2.2升級到4.0,並在寫入數據庫時收到異常。無法轉換'System.Collections.ArrayList'類型的對象來鍵入'System.Collections.Generic.IEnumerable'
this.session.Save(this.Location); // NHibernate.ISession
tx.Commit(); // exception thrown here
例外情況是:
在NHibernate.dll System.InvalidCastException則 '':
該異常是在這個代碼拋出 無法轉換類型的對象'System.Collections.ArrayList' 鍵入'System.Collections.Generic.IEnumerable`1 [System.Object]'。
裏有幾個對象名單被保存,這裏是一對夫婦有代表性的:
protected System.Collections.IList locationList;
public virtual System.Collections.IList AssociatedLocationList
{
get
{
if (this.locationList == null)
{
this.locationList = new System.Collections.ArrayList();
}
return this.locationList;
}
set { this.locationList = value; }
}
protected System.Collections.Generic.IList<Inspection> inspectionList;
public virtual System.Collections.Generic.IList<Inspection> InspectionList
{
get
{
if (this.inspectionList == null)
{
this.inspectionList = new System.Collections.Generic.List<Inspection>();
}
return this.inspectionList;
}
set { this.inspectionList = value; }
}
注意某些具有指定的類型和一些不。
一個建議here被設置爲IList
的財產,但我已經有這樣的。
可以做些什麼?
你有沒有考慮在此使用泛型?拋光裸露的物體似乎非常... 2003. –
我添加了另一個代表性的財產,有一個到原來的職位。你是否建議不要造成這個問題? –
轉換將不再存在於通用版本中。 –