C# NHibernate列表索引映射到不可为空的数据库列

C# NHibernate列表索引映射到不可为空的数据库列,c#,nhibernate,list,indexing,C#,Nhibernate,List,Indexing,我正在尝试使用NHibernate映射一个列表,这是父子关系的一部分。数据库结构为: CREATE TABLE [dbo].[salesvouchers]( [ID] [int] IDENTITY(1,1) NOT NULL, [id_vouchertype] [int] NOT NULL, [id_salespoint] [int] NOT NULL) /*and a couple more fields*/ CREATE TABLE [dbo].[salesvouchersitems]( [

我正在尝试使用NHibernate映射一个列表,这是父子关系的一部分。数据库结构为:

CREATE TABLE [dbo].[salesvouchers](
[ID] [int] IDENTITY(1,1) NOT NULL,
[id_vouchertype] [int] NOT NULL,
[id_salespoint] [int] NOT NULL) /*and a couple more fields*/
CREATE TABLE [dbo].[salesvouchersitems](
[ID] [int] IDENTITY(1,1) NOT NULL,
[id_salesvoucher] [int] NOT NULL,
[itemposition] [int] NOT NULL)
这两个表都由具有外键的id_SalesConcert列关联。问题在于itemposition列是SalesVoucherItem列表的索引。将此映射文件用于Sales凭单类:

<class name="SalesVoucher" table="salesvouchers">
      <id name="Id" column="id">
         <generator class="native" />
      </id>
      <list name="Items" table="salesvouchersitems" lazy="true" cascade="all-delete-orphan">
         <key column="id_salesvoucher"/>
         <index column="itemposition"/>
         <one-to-many class="SalesVoucherItem"/>
      </list>
   <!--and more fields not relevant here-->
   </class>

这似乎很好,但在执行测试以将新的SalesVoucher类插入数据库时,如果列表中有几个SalesVoucherItem,则会抛出SQL错误: “无法将NULL插入itemposition列。列不接受NULL”

NH似乎试图在位置中插入NULL,这对我来说毫无意义,因为列表中的索引是强制数据,应该在数据库中声明为空。
有什么想法吗?谢谢你的帮助!问候。

您必须将itemposition列作为属性公开并设置其值。尼伯内特不能帮你