当我按照官方教程一步一步地运行应用程序时,错误即将到来。
NHibernate.Exceptions.GenericADOException:“could not execute batch command.[SQL: SQL not available]”
SqlException: Conversion failed when converting the nvarchar value '44a0efdef8b648dba4c6a4c67378b7ed' to data type int.
错误区域
ISession session = NHibernateHelper.GetCurrentSession();
try
{
using (ITransaction tx = session.BeginTransaction())
{
myTable princess = new myTable();
princess.Id = "10";
princess.Name = "test";
princess.Sex = "man";
princess.Sal = 1.1f;
session.Save(princess);
tx.Commit();//error is here
}
}
finally
{
NHibernateHelper.CloseSession();
}
这是我的映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="getFromMS" assembly="getFromMS">
<class name="getFromMS.Models.myTable" table="myTable">
<id name="Id">
<column name="Id" sql-type="int" not-null="true"/>
<generator class="uuid.hex" />
</id>
<property name="Name">
<column name="Name" length="50" not-null="true" />
</property>
<property name="Sex">
<column name="Sex" length="10" not-null="true" />
</property>
<property name="Sal">
<column name="Sal" sql-type="float" not-null="true"/>
</property>
</class>
</hibernate-mapping>
出厂配置:
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.connection_string">
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\nhibernate\getFromMS\getFromMS\App_Data\sqlserver.mdf;Integrated Security=True
</property>
<mapping assembly="getFromMS" />
</session-factory>
</hibernate-configuration>
班级:
public class myTable
{
public virtual string Id { set; get; }
public virtual string Name { set; get; }
public virtual string Sex { set; get; }
public virtual float Sal { set; get; }
}