0
次はmssqlのデータベーススクリプトです この部門のテーブルDepartmentはプライマリキーですが自動インクリメントはなく、データ型はvarcharです。.hbm.xmlマッピングファイル内のNHibernateを使用してプライマリキーID列の自動インクリメントを避けることができます
create table Department(
deptid varchar(30) NOT NULL CONSTRAINT deptid_P_KEY PRIMARY KEY,
departmentname varchar(100)
)
以下は私のマッピングファイルです。
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="TestDal" namespace="NHSample.TestDal.Dal" xmlns="urn:nhibernate-mapping-2.2">
<class name="DepartmentEntity" table="Department" lazy="true" >
<id name="DeptId" >
<generator class="assigned" />
<column name="deptid" sql-type="varchar" not-null="true" />
</id>
<property name="Departmentname">
<column name="departmentname" sql-type="varchar" not-null="false" />
</property>
</class>
</hibernate-mapping>
私が実行して構成し、接続文字列パスの時にそれはエラーを与える -
XML validation error: The 'type' attribute is not declared.
次は私の構成コードです:行以下上記のコードで
static Configuration nhConfiguration;
static ISessionFactory nhSessionFactory;
internal static void CreateSessionFactory(string configFilePath)
{
nhConfiguration = new Configuration();
try
{
if (string.IsNullOrEmpty(configFilePath))
nhConfiguration.Configure();
else
nhConfiguration.Configure(configFilePath);
nhConfiguration.SessionFactory().DefaultFlushMode(flushMode);
}
catch (Exception exception)
{
throw new NHException("Failed to configure session factory.", exception);
}
try
{
nhSessionFactory = nhConfiguration.BuildSessionFactory();
}
}
はエラーになります: nhConfiguration.Configure(configFilePath);
どのようにnhibernateを使用してこれを行うには。 type
属性はオプションであり、基本的なプロパティが同じ型である場合は省略することができ
<id name="DeptId" generator="assigned" column="deptid" type="string"/>
:
私のアプリケーションでこのソリューションが正しく動作するDavidに感謝します。 –