添加冲突替换到 Nhibernate 映射文件
Add on conflict replace to Nhibernate mapping file
我正在其中编写一个应用程序我正在使用 NHibernate
和 SQLite
。
我有一个 table 有一个列,我希望它是唯一的并且在发生冲突时替换。
这是我的 .hbm.xml
映射文件代码。
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TaxeeManager"
namespace="TaxeeManager.Database">
<class name="Office" table="offices">
<id name="Id" column="id">
<generator class="identity" />
</id>
<property name="Name" column="name" />
<property name="Address" column="address" />
<property name="ManagerName" column="managername" />
<property name="Email" column="email" />
<property name="WebSite" column="website" />
<property name="Phone1" column="phone1" />
<property name="Phone2" column="phone2" />
<property name="Phone3" column="phone3" />
<property name="Picture" column="picture" />
<property name="Mid" column="mid" unique="true"/>
<property name="RegisterId" column="registerid" />
<property name="Latitude" column="latitude" />
<property name="Longitude" column="longitude" />
</class>
</hibernate-mapping>
我的唯一列是 mid
。
我的table
终于要这样了
CREATE TABLE offices (id integer primary key autoincrement, name TEXT, address TEXT, managername TEXT, email TEXT, website TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, picture TEXT, mid BIGINT UNIQUE ON CONFLICT REPLACE, registerid TEXT, latitude DOUBLE, longitude DOUBLE)
我该怎么做?
亲爱的 Mohammad Reza 我认为您最常使用纯 SQL 代码通过此函数创建此约束:
session.CreateSQLQuery("CREATE TABLE offices (id integer primary key autoincrement, name TEXT, address TEXT, managername TEXT, email TEXT, website TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, picture TEXT, mid BIGINT UNIQUE ON CONFLICT REPLACE, registerid TEXT, latitude DOUBLE, longitude DOUBLE)").ExecuteUpdate();
希望对您有所帮助:)
我正在其中编写一个应用程序我正在使用 NHibernate
和 SQLite
。
我有一个 table 有一个列,我希望它是唯一的并且在发生冲突时替换。
这是我的 .hbm.xml
映射文件代码。
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TaxeeManager"
namespace="TaxeeManager.Database">
<class name="Office" table="offices">
<id name="Id" column="id">
<generator class="identity" />
</id>
<property name="Name" column="name" />
<property name="Address" column="address" />
<property name="ManagerName" column="managername" />
<property name="Email" column="email" />
<property name="WebSite" column="website" />
<property name="Phone1" column="phone1" />
<property name="Phone2" column="phone2" />
<property name="Phone3" column="phone3" />
<property name="Picture" column="picture" />
<property name="Mid" column="mid" unique="true"/>
<property name="RegisterId" column="registerid" />
<property name="Latitude" column="latitude" />
<property name="Longitude" column="longitude" />
</class>
</hibernate-mapping>
我的唯一列是 mid
。
我的table
终于要这样了
CREATE TABLE offices (id integer primary key autoincrement, name TEXT, address TEXT, managername TEXT, email TEXT, website TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, picture TEXT, mid BIGINT UNIQUE ON CONFLICT REPLACE, registerid TEXT, latitude DOUBLE, longitude DOUBLE)
我该怎么做?
亲爱的 Mohammad Reza 我认为您最常使用纯 SQL 代码通过此函数创建此约束:
session.CreateSQLQuery("CREATE TABLE offices (id integer primary key autoincrement, name TEXT, address TEXT, managername TEXT, email TEXT, website TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, picture TEXT, mid BIGINT UNIQUE ON CONFLICT REPLACE, registerid TEXT, latitude DOUBLE, longitude DOUBLE)").ExecuteUpdate();
希望对您有所帮助:)