在我的代码中,当会话打开并连接时,在调用List()方法之后:
using (ISession NSession = SessionProvider.GetSession())
{
ICriteria CriteriaQuery =
NSession.CreateCriteria(typeof(Application));
return (List<Application>) CriteriaQuery.List<Application>();
}
它不检索任何数据而只是“{}”,这是Application Class及其映射XML代码:
public class Application
{
private string _name;
private Developer _developer;
private int _id;
private List<Bug> _bugs;
public Application()
{
_bugs = new List<Bug>();
}
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; }
}
}
和
<?xml version="1.0" encoding="utf-8" ?>
<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>
答案 0 :(得分:0)
你确定return (List<Application>) CriteriaQuery.List<Application>();
上没有异常?
据我所知,nhibernate需要集合接口,所以它可以插入自己的转换。您可以尝试将List<Bug>
更改为IList<Bug>