我有一张表:
CREATE TABLE [dbo].[MOVIES_HISTORY](
[DATE] [datetime] NOT NULL,
[COUNT] [int] NOT NULL CONSTRAINT [DF_MOVIES_HISTORY_COUNT] DEFAULT ((0)),
CONSTRAINT [PK_MOVIES_HISTORY] PRIMARY KEY CLUSTERED
(
[DATE] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
类别:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Kinoplex.Models
{
public class MoviesHistory
{
private DateTime date;
private int count;
public DateTime Date
{
get
{
return date;
}
set
{
date = value;
}
}
public int Count
{
get
{
return count;
}
set
{
count = value;
}
}
}
}
映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Kinoplex.Models"
assembly="Kinoplex">
<class name="MoviesHistory"
dynamic-insert="true"
dynamic-update="true"
lazy="false"
table="MOVIES_HISTORY">
<id name ="Date" column="DATE" type="datetime">
</id>
<property name ="Count" >
<column name="COUNT" sql-type="int" not-null="true"></column>
</property>
</class>
</hibernate-mapping>
其他每个班级都在工作,我对这个班级只有问题。
执行以下查询:
IQuery query = this.session.CreateQuery("from MoviesHistory");
导致异常:
MoviesHistory未映射[来自MoviesHistory]
任何人都可以告诉我出了什么问题?我怀疑id列可能有误,但找不到任何相关内容。
答案 0 :(得分:4)
确保您的.hbm.xml
在项目中将其构建操作设置为嵌入式资源,否则在nHibernate启动时它不会包含在映射中。
另外,不重要的是它很重要,但是DateTime
应该有适当的套管才能安全(不确定nHibernate解析器是否关心它,它不是在某一点上):
<id name="Date" column="DATE" type="DateTime">