2013-10-31 2 views
1

NHibernate.i의 새 기능입니다. nhibernate에 문제가 있습니다. 메인 테이블에서 쿼리를 실행하면 주 테이블 레코드가 생기지 만 관련 링크 테이블 테이블 레코드도 제공됩니다. 그래서 더 많은 SQL 쿼리가 데이터베이스에서 발생했습니다. 내 query.i의 성능이 저하되고 메인 테이블 레코드 만 필요하며 데이터베이스의 다른 쿼리는 실행되지 않습니다.NHibernate는 하나 이상의 테이블 레코드를 가져옵니다.

내가 TAPVendor 테이블 레코드를 원하는 경우에만 다음

내가이

VAR lstTAPVendor = session.Query < TAPVendor>()

데이터베이스에서 내가 해고하고 쿼리에서 내 C# 코드입니다 또한 납본업자의 .hbm 파일을 붙였다

<?xml version="1.0" encoding="utf-8"?> 
<hibernate-mapping namespace="M3.Entities" assembly="M3.Entities" xmlns="urn:nhibernate-mapping-2.2"> 
    <class name="TAPVendor" table="tAPVendor" schema="dbo"> 
    <id name="FVendorID" type="Guid"> 
     <generator class="assigned" /> 
    </id> 
    <version name="FTimestamp" generated="always" unsaved-value="null" type="BinaryBlob"> 
     <column name="FTimestamp" not-null="true" sql-type="timestamp"/> 
    </version> 
    <property name="FActive" type="Boolean" not-null="true" /> 

    <property name="FTermsType" type="Int32" precision="10" not-null="true" /> 
    <property name="FACHPayment" type="Boolean" not-null="true" /> 
    <property name="FCompanyName" type="String" length="50" not-null="true" /> 
    <property name="FAccrueUseTax" type="Boolean" not-null="true" /> 
    <property name="FSinglePaymentVendor" type="Boolean" not-null="true" /> 
    <property name="FACHEnabled" type="Boolean" not-null="true" /> 
    <property name="FCheckPerInvoice" type="Boolean" not-null="true" /> 
    <property name="FBankAccountType" type="Int32" precision="10" not-null="true" /> 
    <property name="FBankAccountName" type="String" length="50" /> 
    <property name="FBankAccountNumber" type="String" length="50" /> 
    <property name="FBankABANumber" type="String" length="50" /> 
    <property name="FLegalName" type="String" length="50" /> 
    <property name="FDateAdded" type="DateTime" /> 
    <property name="FAddedBy" type="String" length="50" /> 
    <property name="FDateModified" type="DateTime" /> 
    <property name="FModifiedBy" type="String" length="50" /> 
    <property name="FAccountNo" type="Double" precision="53" /> 
    <property name="FDescription" type="String" length="100" /> 
    <property name="FTerms" type="Int32" precision="10" /> 
    <property name="F1099Box" type="Int16" precision="5" /> 
    <property name="F1099Type" type="String" length="15" /> 
    <property name="FTaxID" type="String" length="10" /> 
    <property name="FSSN" type="String" length="11" /> 
    <property name="FVendorNo" type="String" length="10" /> 
    <property name="FAccountNo2" type="Double" precision="53" not-null="false" /> 
    <property name="FIsUseAccountNo2" type="Boolean" not-null="true" /> 
    <many-to-one name="TAddres" class="TAddres" column="fAddressID" /> 
    <many-to-one name="TSCCompany" class="TSCCompany" column="fCompanyID" /> 
    <many-to-one name="TContact" class="TContact" column="fContactID" /> 
    <many-to-one name="TSCEnterprise" class="TSCEnterprise" column="fEnterpriseID" /> 
    <many-to-one name="TSCProperty" class="TSCProperty" column="fPropertyID" /> 
    <set name="TAPInvoices" table="tAPInvoice" inverse="true"> 
     <key column="fVendorID" /> 
     <one-to-many class="TAPInvoice" /> 
    </set> 
    <set name="TBAChecks" table="tBACheck" inverse="true"> 
     <key column="fVendorID" /> 
     <one-to-many class="TBACheck" /> 
    </set> 
    <set name="TAPRecurringInvoices" table="tAPRecurringInvoice" inverse="true"> 
     <key column="fVendorID" /> 
     <one-to-many class="TAPRecurringInvoice" /> 
    </set> 
    <set name="TGLPostMasters" table="tGLPostMaster" inverse="true"> 
     <key column="fVendorID" /> 
     <one-to-many class="TGLPostMaster" /> 
    </set> 
    </class> 
</hibernate-mapping> 

답변

1

어떤 솔트가있다 이온을 쉽게 얻을 수 있음 - 1. <set> 매핑을 제거하거나 매핑을 제거하지 않고 다른 항목을 만듭니다. 2. 모두 설정 <set lazy="true">...</set> 가져 오기는 이러한 속성에 액세스 할 때만 발생합니다. 3. DTO (데이터 전송 개체) 엔터티, 라이트 버전을 만들고 NHibernate.Projections 라이브러리를 사용하여 속성을 선택적으로 가져옵니다. 4. 하나의 조인 된 쿼리에서 모든 데이터를 가져 오도록 <set fetch="join">...</set>을 설정하십시오. 이렇게하면 레코드가 중복 될 수 있으므로주의하십시오.

일반적으로 쿼리를 분리하는 NH가 반드시 나쁜 것은 아니며, 큰 테이블에서 JOIN하면 성능이 크게 저하 될 수 있습니다. 문제가 매핑 문제가 아니거나 DB 또는 코드 문제 일 수 있습니다.