NHibernate的一个问题
我仿照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();
错误信息如下:
不能从目标类型扩展到基元类型
哪位大虾能帮我看看这是什莫问题!!!
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();
错误信息如下:
不能从目标类型扩展到基元类型
哪位大虾能帮我看看这是什莫问题!!!
...全文
相关推荐
NHibernate帮助手册
此外,学习 NHibernate 时,可能会遇到文档不全的问题,可以参考社区的翻译和讨论,以及实践经验的分享,共同进步。
mygenereation模板 NHibernate DDL的好久没有更新了
标题提及的“myGeneration模板 NHibernate DDL好久没有更新”,这意味着可能社区维护的myGeneration模板可能不适用于较新的NHibernate版本,导致在使用过程中出现兼容性问题
NHibernate学习笔记
### NHibernate学习笔记知识点梳理#### 一、NHibernate简介及基本概念- **NHibernate** 是一个开源的对象关系映射(ORM)解决方案,用于.NET框架。
NHibernate的小例子
NHibernate 是一个强大的对象关系映射(ORM)框架,它为.NET 应用程序提供了数据库持久化的解决方案。
Nhibernate代码生成模板v1_1.rar
NHibernate代码生成模板v1_1"着重于修复了v1.0版本的一个主要问题,即在处理复合主键时,实体类在运行时会引发Nhibernate错误。


