我的映射(经过编辑和简化以保护不那么无辜的人):
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyAssembly, Culture=neutral"
namespace="MyAssembly" auto-import="false">
<class name="Customer" table="Customers">
<id name="Id" access="nosetter.camelcase-underscore" >
<generator class="assigned"/>
</id>
<property name="blah"/>
...
<property name="bleh"/>
<join table="Addresses" optional="true">
<key column="Id"/>
<component name="Address" class="MyAssembly.Address, MyAssembly, Culture=neutral" access="field.camelcase-underscore">
<property name="Street" />
<property name="Number" />
</component>
</join>
</class>
</hibernate-mapping>
当我这样做时:
Address dir = new Address();
dir.Street = "Foo";
dir.Number = 27;
//// Previously loaded customer
cli.Address = dir;
//// Save repository, commit transaction
这工作正常,并自动将新地址插入地址表。但是,如果我想删除地址:
//// Previously loaded customer with attached address
cli.Address = null;
//// Save repository, commit transaction
也就是说,NHibernate 不会从 Addresses 表中删除行来更新它,而是将其所有字段设置为空,除了 Id。
我的映射有什么问题?