the stack:
Code:
[InvalidCastException: 无法将类型为([color=#FF0000]Can not cast [/color])“NHibernate.Collection.Generic.PersistentGenericSet`1[qianhu.dadi.model.Catalog]”的对象强制转换为类型([color=#FF0000]strongly into [/color])“System.Collections.Generic.IList`1[qianhu.dadi.model.Catalog]”。]
(Object , Object[] , SetterCallback ) +210
NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues(Object target, Object[] values) +42
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values) +66
[PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of qianhu.dadi.model.Catalog]
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values) +157
NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValues(Object entity, Object[] values) +82
NHibernate.Persister.Entity.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values, EntityMode entityMode) +47
NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity, Boolean readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent) +1012
NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session, Boolean readOnly) +390
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +958
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +94
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +167
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +38
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +130
NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) +58
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +541
NHibernate.Impl.CriteriaImpl.List(IList results) +62
NHibernate.Impl.CriteriaImpl.List() +87
qianhu.dadi.dal.CatalogDal.checkExistsByName(String name) in G:\website\qianhu\dadi\dadiLib\dal\CatalogDal.cs:65
qianhu.dadi.service.CatalogService.checkExistsByName(String name) in G:\website\qianhu\dadi\dadiLib\service\CatalogService.cs:34
forum_addCatalog1.Button1_Click(Object sender, EventArgs e) in g:\website\qianhu\dadi\dadiSite\forum\addCatalog1.aspx.cs:28
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3824
My Class:
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace qianhu.dadi.model
{
public class Catalog
{
/// <summary>
/// 编号
/// </summary>
private int cid;
public virtual int Cid
{
get { return cid; }
set { cid = value; }
}
/// <summary>
/// 分类名
/// </summary>
private String name;
public virtual String Name
{
get { return name; }
set { name = value; }
}
/// <summary>
/// 父分类
/// </summary>
private Catalog parent;
public virtual Catalog Parent
{
get { return parent; }
set { parent = value; }
}
/// <summary>
/// 子分类
/// </summary>
private IList<Catalog> children;
public virtual IList<Catalog> Children
{
get { return children; }
set { children = value; }
}
/// <summary>
/// 分类
/// </summary>
public Catalog()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private IList<Message> messages;
public virtual IList<Message> Messages
{
get { return messages; }
set { messages = value; }
}
}
}
My mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="qianhu.dadi.model" assembly="qianhu.dadi">
<class name="Catalog" table="dadi_Catalog">
<id name="Cid">
<column name="Cid" not-null="true"/>
<generator class="identity" />
</id>
<property name="Name" type="String"/>
<many-to-one name="Parent" class="Catalog" column="Parent_ID" lazy="false" not-null="false" />
<set name="Children" inverse="true" lazy="false">
<key column="Parent_ID"/>
<one-to-many class="Catalog"/>
</set>
<set name="Messages" inverse="true" lazy="false">
<key column="Cid"/>
<one-to-many class="Message"/>
</set>
</class>
</hibernate-mapping>
My Code:
Code:
public bool checkExistsByName(string name)
{
ISession session = NHibernateHelper.GetCurrentSession();
IList<Catalog> catalogs = session.CreateCriteria<Catalog>().Add(Restrictions.Like("Name", name)).List<Catalog>();
NHibernateHelper.CloseSession();
if (catalogs.Count > 0)
{
return true;
}
else {
return false;
}
}
I hava tried a lot of places,hereis the last hope. :(