NHibernate 구현 및 지연로드 사용 프로젝트가 있습니다. 이 프로젝트에는 Person 클래스와 PersonIdentity 클래스가 있습니다. 그 둘 사이의 관계는 집합체이며, 사람이 한 PersonIdentity를 가졌다는 것을 의미합니다.NHibernate 쿼리 및 최상의 성능 최적화 방법
사람 매핑은 다음과 같습니다
<class name="Person" table="Person_Person" >
<id name="Id" type="Int64" unsaved-value="0">
<generator class="native" />
</id>
<version name="Version" />
<property name="Name" column="Name"
type="String(255)" access="property" not-null="false" />
<one-to-one name="Identity" property-ref="Person"
class="Domain.Entities.PersonIdentity,Domain.Entities" cascade="delete" fetch="select" />
</class>
PersonIdentity 매핑은 다음과 같습니다
<id name="Id" type="Int64" unsaved-value="0" >
<generator class="native" />
</id>
<property name="FirstName" column="FirstName" type="String(255)" access="property" not-null="false" />
<property name="LastName" column="LastName" type="String(255)" access="property" not-null="false" />
<many-to-one name="Person" column="Person_id_fk" uniqe="true" class="Domain.Entities.Person,Domain.Entities"
outer-join="auto" fetch="select" access="property" not-null="true" />
</class>
내 문제는 성능이다. 이 같은 유일한 사람에 쿼리를 실행하면 :
SELECT * FROM Person_Identiyt WHERE Id = 1;
SELECT * FROM Person_Identiyt WHERE Id = 2;
SELECT * FROM Person_Identiyt WHERE Id = 3;
...
:
var q = SessionInstance.Query<Person>();
IList list = q.ToList<Person>();
을 난 단지, 데이터베이스 인당
SELECT * FROM Person_Person
그러나 추가를 실행과 같은 쿼리를 실행 기대
그리고 게으른 접근 방식에 따르면 좋지 않습니다. PersonIdentity는 호출하기 전에로드해야합니다. 맨 처음로드 할 때 PersonIdentity가없는 Person 만로드 할 수 있습니까?
항상 사람 – Ehsan