NHibernate的一个问题

huangskar 2005-01-24 11:53:53
我仿照Hibernate的中文手册做了一个 类,就使用了手册里里胡类Cat,类的结构如下:
public class Cat
{
public Cat()
{
}
private string catID;
private string sex;
private double weight;
dd private System.DateTime birthDay;
private Cat mate;
private IDictionary kittens = new Hashtable();
public string CatID
{
get {return catID;}
set {catID = value;}
}
public string Sex
{
get {return sex;}
set {sex = value;}
}
public double Weight
{
get {return weight;}
set {weight = value;}
}
public DateTime BirthDay
{
get {return birthDay;}
set {birthDay = value;}
}
public Cat Mate
{
get {return mate;}
set {mate = value;}
}
public IDictionary Kittens
{
get {return kittens;}
set {kittens = value;}
}
}
使用的映射文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhbDemo.BusinessEntity.Cat, nhbDemo" table="cats">
<id name="CatID" column="catid" type="String(40)">
<generator class="assigned" />
</id>
<property name="BirthDay" type="DateTime"/>
<property name="Weight" type="String(40)"/>
<property name="Sex" type="String(20)"/>
<many-to-one name="Mate" column="mate_id" class="nhbDemo.BusinessEntity.Cat, nhbDemo"/>
<set name="Kittens" table="cats">
<key column="parent_id"/>
<one-to-many class="nhbDemo.BusinessEntity.Cat, nhbDemo"/>
</set>
</class>
</hibernate-mapping>
数据库cats镖的结构如下:
sex
weight
catid 这是prime key
birthdy
mate_id
parent_id

然后我在page_load调用如下的代码:
IList catList = session.CreateCriteria(typeof(Cat)).List();
错误信息如下:
不能从目标类型扩展到基元类型
哪位大虾能帮我看看这是什莫问题!!!



...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
readersm68 2005-02-18
  • 打赏
  • 举报
回复
或者
IDictionary catList = session.CreateCriteria(typeof(Cat)).IDictionary ();
jiezhi 2005-02-18
  • 打赏
  • 举报
回复
把配置文件中的
<set name="Kittens" table="cats">
<key column="parent_id"/>
<one-to-many class="nhbDemo.BusinessEntity.Cat, nhbDemo"/>
</set>
改为:
<bag name="Kittens" table="cats">
<key column="parent_id"/>
<one-to-many class="nhbDemo.BusinessEntity.Cat, nhbDemo"/>
</bag>
代码:
private IDictionary kittens = new Hashtable();
public IDictionary Kittens
{
get {return kittens;}
set {kittens = value;}
}
改为:
private IList kittens ;
public IList Kittens
{
get {return kittens;}
set {kittens = value;}
}
然后再试试看
readersm68 2005-02-18
  • 打赏
  • 举报
回复
IList catList = session.CreateCriteria(typeof(Cat)).List();
这句应该有问题吧
chsfly 2005-02-18
  • 打赏
  • 举报
回复
在NHibernate中类好象不能嵌套.你去掉
public Cat Mate
{
get {return mate;}
set {mate = value;}
}
再试试看.

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧