Nhibernate报错集合类型转换错误!
这我的实体类映射文件
这我的实体类
报错信息:注:不是配置的问题,我执行增、删、改、查都可以唯独查的类中包含集合的时候就报转换无效!我知道什么原因请给位指教!报错信息不完整的话 加QQ:498795832 详聊 在线等!!!!非常急
Message:Invalid Cast (check your mapping for property type mismatches); setter of MyBookShop.Model.Book
InnerException:{"指定的转换无效。"}
StackTrace: 在 (Object , Object[] , SetterCallback )
在 NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues(Object target, Object[] values)
在 NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyBookShop.Model.Book, MyBookShop.Model" table="Books">
<id name="Id" type="Int32" unsaved-value="null">
<column name="Id" length="4" sql-type="int" not-null="true" unique="true" index="PK_Book"/>
<generator class="native" />
</id>
<property name="Title" type="String">
<column name="Title" length="200" sql-type="nvarchar" not-null="true"/>
</property>
<property name="Author" type="String">
<column name="Author" length="200" sql-type="nvarchar" not-null="true"/>
</property>
<property name="PublishDate" type="DateTime">
<column name="PublishDate" length="8" sql-type="datetime" not-null="true"/>
</property>
<property name="ISBN" type="String">
<column name="ISBN" length="50" sql-type="nvarchar" not-null="true" unique="true" index="IX_Books_ISBN"/>
</property>
<property name="WordsCount" type="Int32">
<column name="WordsCount" length="4" sql-type="int" not-null="true"/>
</property>
<property name="UnitPrice" type="Decimal">
<column name="UnitPrice" length="8" sql-type="money" not-null="true"/>
</property>
<property name="ContentDescription" type="String">
<column name="ContentDescription" sql-type="nvarchar" not-null="false"/>
</property>
<property name="AurhorDescription" type="String">
<column name="AurhorDescription" sql-type="nvarchar" not-null="false"/>
</property>
<property name="EditorComment" type="String">
<column name="EditorComment" sql-type="nvarchar" not-null="false"/>
</property>
<property name="TOC" type="String">
<column name="TOC" sql-type="nvarchar" not-null="false"/>
</property>
<property name="Clicks" type="Int32">
<column name="Clicks" length="4" sql-type="int" not-null="true"/>
</property>
<many-to-one name="Category" class="MyBookShop.Model.Category, MyBookShop.Model" foreign-key="FK_Book_Category">
<column name="CategoryId" length="4" sql-type="int" not-null="true"/>
</many-to-one>
<many-to-one name="Publisher" class="MyBookShop.Model.Publisher, MyBookShop.Model" foreign-key="FK_Books_Publishers">
<column name="PublisherId" length="4" sql-type="int" not-null="true"/>
</many-to-one>
<bag name="BookReaderCommentses" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="BookId"/>
<one-to-many class="MyBookShop.Model.ReaderComment, MyBookShop.Model"/>
</bag>
</class>
</hibernate-mapping>
这我的实体类
using System;
using System.Collections.Generic;
using System.Text;
namespace MyBookShop.Model
{
[Serializable()]
public class Book
{
#region 字段
private int id;
private string title;
private string author;
private Publisher publisher;
private DateTime publishDate;
private string iSBN;
private int wordsCount;
private int unitPrice;
private string contentDescription;
private string aurhorDescription;
private string editorComment;
private string tOC;
private Category category;
private int clicks;
private List<ReaderComment> bookReaderCommentses = null;
#endregion
#region 属性
public virtual List<ReaderComment> BookReaderCommentses
{
get { return bookReaderCommentses; }
set { bookReaderCommentses = value; }
}
public virtual string ContentDescription
{
get { return contentDescription; }
set { contentDescription = value; }
}
public virtual DateTime PublishDate
{
get { return publishDate; }
set { publishDate = value; }
}
public virtual int Clicks
{
get { return clicks; }
set { clicks = value; }
}
public virtual Category Category
{
get { return category; }
set { category = value; }
}
public virtual string TOC
{
get { return tOC; }
set { tOC = value; }
}
public virtual string EditorComment
{
get { return editorComment; }
set { editorComment = value; }
}
public virtual string AurhorDescription
{
get { return aurhorDescription; }
set { aurhorDescription = value; }
}
public virtual int UnitPrice
{
get { return unitPrice; }
set { unitPrice = value; }
}
public virtual int WordsCount
{
get { return wordsCount; }
set { wordsCount = value; }
}
public virtual string ISBN
{
get { return iSBN; }
set { iSBN = value; }
}
public virtual Publisher Publisher
{
get { return publisher; }
set { publisher = value; }
}
public virtual string Author
{
get { return author; }
set { author = value; }
}
public virtual string Title
{
get { return title; }
set { title = value; }
}
public virtual int Id
{
get { return id; }
set { id = value; }
}
#endregion
}
}
报错信息:注:不是配置的问题,我执行增、删、改、查都可以唯独查的类中包含集合的时候就报转换无效!我知道什么原因请给位指教!报错信息不完整的话 加QQ:498795832 详聊 在线等!!!!非常急
Message:Invalid Cast (check your mapping for property type mismatches); setter of MyBookShop.Model.Book
InnerException:{"指定的转换无效。"}
StackTrace: 在 (Object , Object[] , SetterCallback )
在 NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues(Object target, Object[] values)
在 NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values)
...全文
相关推荐
nhibernate 代码生成工具(nhibernate helper kit)
使用Nhibernate Helper Kit可以快速生成这些代码,让开发者专注于业务逻辑的实现。2. **减少错误**:自动化的代码生成降低了手动编写时可能引入的错误,确保了代码的准确性和一致性。
NHibernate 3.0 经典教程
- **集合映射**:定义对象集合与数据库表之间的映射关系。**4.
Nhibernate代码生成器
**减少错误**:自动化的代码生成减少了人为输入错误的可能性。3. **保持一致性**:所有实体和映射都遵循统一的模板,确保代码风格一致。4.
NHibernate实现ORM
><hibernate-configuration xmlns="urn:nhibernate-configuration-2.0"> <session-factory> <!
NHibernate.rar所有需要添加的引用功能包
在使用 NHibernate 进行数据库操作时,log4net 可以帮助开发者跟踪和调试错误,记录查询性能等信息,这对于优化应用和排查问题非常有帮助。


