我有 2 个实体 Person 和 Address,Person 有一个地址。
编辑:地址已经存在,我只是想保存外键。
当我这样做时:
PersonDTO person = new PersonDTO();
person.Age = "Bob";
person.Address = new AddressDTO {Key = 123};
Save(person);
我得到这个例外:
无法将值 NULL 插入到列“键”、表“地址”中;列不允许空值。INSERT 失败。语句已终止。
从 Person 映射文件片段
<class name="PersonDTO" table="Person" xmlns="urn:nhibernate-mapping-2.2">
<id name="Key" column="PersonKey" type="Guid">
<generator class="guid" />
</id>
<one-to-one name="Address" class="AddressDTOl" />
</class>
我不明白为什么会发生这种情况,我给地址键一个值。我的方法有缺陷吗?