고객이 여러 연락처를 가질 수 있습니다. 아래 코드는 작동하지만이 고객의 연락처는 먼저 삭제되고 다시 삽입 된 후 삭제됩니다. 이 삭제를 피하고 새로운 것을 삽입하는 것은 불가능합니까? NHibernate : 다 대다 콜렉션
<class name="Customer" table="Customer">
<id name="Id">
<generator class="native" />
</id>
<property name="LastName" not-null="true" />
<bag name="Contacts" cascade="all-delete-orphan" table="CustomerContact">
<key column="Customer" not-null="true" />
<many-to-many class="Contact"/>
</bag>l
</class>
<class name="Contact" table="Contact">
<id name="Id">
<generator class="native" />
</id>
<property name="LastName" not-null="true" />
<many-to-one name="Customer" column="Customer" not-null="true" />
</class>
public virtual void AddContact(Contact contact)
{
Contacts.Add(contact);
contact.Customer = this;
}
내가 두 번이 코드를 할
2 연락처를 추가합니다 : NH 컬렉션에 대한 지속 정보를 잃었을 때Contact contact = new Contact() { LastName = "MyLastName" };
Customer customer = session.Get(customerId);
customer.AddContact(contact);
session.Update(customer);
변경 후 업데이트 (고객)를 호출 할 필요가 없습니다. 그것은 세션에 있으며 자동으로 업데이트됩니다. –
부동산 연락처는 어떻게 구현됩니까? –