두 클래스가 있습니다. 하나는 Employee
이고 나머지 하나는 'Employee'
클래스와 0 또는 하나의 관계가있는 다른 EmployeeDetails
입니다. 즉,이 'EmployeeDetails'
클래스에 추가 데이터를 저장해야하는 경우가 있지만 이는 반드시 일반적인 것은 아닙니다. db 구조는 'EmployeeDetails'가 부모와 동일한 ID를 공유함으로써 매우 간단합니다.nHibernate, 1에서 0 또는 하나의 관계로 불행
클래스에서 'EmployeeDetails'
클래스를 삭제하는 문제는 개체를 null로 설정하면 트릭과 플러시 세션을 수행했지만 DB의 레코드가 제거되지 않는다고 생각했을 것입니다.
내 매핑은 ...입니다
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="StudioBusinessLayer.Data.Structure.Employee, StudioBusinessLayer" table="tblEmployee" lazy="false">
<id name="ID" column="ID" type="int">
<generator class="native" />
</id>
<property name="Name" column="Name" not-null="true" type="string" length="100" />
<!-- etc -->
<one-to-one constrained="false" name="EmployeeDetails" class="StudioBusinessLayer.Data.Structure.EmployeeDetails, StudioBusinessLayer" cascade="all-delete-orphan" />
</class>
</hibernate-mapping>
... 그리고 EmployeeDetails 클래스 ...
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="StudioBusinessLayer.Data.Structure.EmployeeDetails, StudioBusinessLayer" table="tblDetails" lazy="false">
<id name="ID" column="DetailsID" type="int">
<generator class="foreign">
<param name="property">Employee</param>
</generator>
</id>
<property name="Address" column="Address" not-null="false" type="string" length="1000" />
<property name="ContactEmail" column="ContactEmail" not-null="false" type="string" length="255" />
<property name="ContactName" column="ContactName" not-null="false" type="string" length="255" />
<property name="ContactTelephone" column="ContactTelephone" not-null="false" type="string" length="255" />
<property name="ZipCode" column="ZipCode" not-null="true" type="string" length="100" />
<many-to-one name="Employee" class="StudioBusinessLayer.Data.Structure.Employee, StudioBusinessLayer" column="DetailsID" insert="false" update="false"></many-to-one>
</class>
</hibernate-mapping>
삽입 및 업데이트
가 잘 작동,하지만 난을 찾기 위해 애 쓰고 있었어요 스위치를 사용하면이 작업을 삭제할 수 있습니다.어떤 도움이나 제안은 감사받은 ...
고맙지 만 nHibernate 구현이 훌륭하지는 않지만이 물건은 비즈니스 계층에서 처리 할 수 있으므로 걱정하지 않아도된다. 건배 – SeanCocteau