public List<Application> FindAll()
{
using (ISession NSession = SessionProvider.GetSession())
{
ICriteria CriteriaQuery =
NSession.CreateCriteria(typeof(Application));
return (List<Application>) CriteriaQuery.List<Application>();
}
}
私は、アプリケーションのクラスには、次のされている例外を取得しています:型のオブジェクトをキャストすることができません「NHibernate.Collection.Generic.PersistentGenericBag」
public class Application
{
private string _name;
private Developer _developer;
private int _id;
private List<Bug> _bugs;
public Application()
{
}
public virtual int ApplicationId
{
get { return _id; }
set { _id = value; }
}
public virtual Developer Developer
{
get { return _developer; }
set { _developer = value; }
}
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
public virtual List<Bug> Bugs
{
get { return _bugs; }
set { _bugs = value; }
}
}
System.InvalidCastExceptionの:のオブジェクトをキャストすることができませんがタイプ 'NHibernate.Collection.Generic.PersistentGenericBag 1[BugTracker.Model.Bug]' to type 'System.Collections.Generic.List
1 [BugTracker.Model.Bug]'。ここで
はapplication.hbm.xmlです:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BugTracker.Model"
assembly="BugTracker">
<class name="Application" table="Applications" lazy="false">
<id name="ApplicationId" column ="ApplicationId" type="int" unsaved-value ="0">
<generator class ="native"></generator>
</id>
<property name ="Name" column="Name"/>
<component access ="field.camelcase-underscore" name ="Developer"
class="Developer">
<property access ="field.camelcase-underscore"
column ="DeveloperFirstName" name="FirstName"/>
<property access ="field.camelcase-underscore"
column="DeveloperLastName" name="LastName"/>
</component>
<bag cascade="all-delete-orphan"
inverse ="true"
name ="Bugs"
lazy="false"
access ="field.camelcase-underscore">
<key column ="ApplicationId"/>
<one-to-many class ="Bug"/>
</bag>
</class>
</hibernate-mapping>
私はNHibernateのに初心者だと、それは非常に複雑見つけます。私は本当に問題を見ることができません。 例外は、アプリケーションクラスコンストラクターの最後の行で発生します。
アプリケーションクラスのコンストラクタで例外が発生しますが、なぜそうですか? – FidEliO
行16:{ 行17:_bugs =新しいリスト(); 18行目:} –
FidEliO
[NHibernate.Collection.Generic型のオブジェクトをキャストできません。PersistentGenericBagをリストに]](0120-18753)[編集] –