2010-03-04 6 views
3

안녕하세요, 저는 여기에서 완전히 벗어 났을지도 모르겠지만, 저는 여전히 내게 그렇게 맨손으로 새 것처럼 느껴지지 않습니다.nhibernate가 동적으로 클래스를 묶습니다.

이 기사

http://www.mattfreeman.co.uk/2009/01/nhibernate-21-trunk-entity-name-some-inheritance-and-dynamic-component/

을 읽었습니다 그리고 동적으로 사용하여 다른 테이블에 바인딩 런타임에 내 매핑을 변경하는 방법을 찾고 있어요

일대의 값을에 의존 내 부모 개체. 여기

내 매핑

<bag name="Data" mutable="true" > 
    <key> 
     <column name="Log_Link" /> 
     <column name="channel" /> 
    </key> 
    <one-to-many class="Fluent.Entities.Meters.FTIMeterChannelData, Poco" entity-name="30" /> 
</bag> 

지금

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"> 
    <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Fluent.Entities.Meters.FTIMeterChannelData, Poco" table="loggerData" entity-name="30"> 
    <composite-id mapped="false" unsaved-value="undefined"> 
     <key-property name="Channel" type="System.Int32"> 
     <column name="channel" /> 
     </key-property> 
     <key-property name="LogLink" type="System.Int32"> 
     <column name="Log_Link" /> 
     </key-property> 
    </composite-id> 
    <property name="Date" type="System.DateTime"> 
     <column name="hhdate" /> 
    </property> 
    </class> 

    <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Fluent.Entities.Meters.FTIMeterChannelData, Poco" table="loggerData10" entity-name="15"> 
    <composite-id mapped="false" unsaved-value="undefined"> 
     <key-property name="Channel" type="System.Int32"> 
     <column name="channel" /> 
     </key-property> 
     <key-property name="LogLink" type="System.Int32"> 
     <column name="Log_Link" /> 
     </key-property> 
    </composite-id> 
    <property name="ReadingType" type="System.Char"> 
     <column name="readingtype" /> 
    </property> 
    </class> 
</hibernate-mapping> 

문서 상태로 나는 이제 질문을 인터셉터

class LoggerDataInterceptor : EmptyInterceptor 
    { 
     public override string GetEntityName(object entity) 
     { 
      return Convert.ToString("20"); 
     } 
    } 

를 사용하여 엔티티 이름을 변경 할 수 있어야한다

있습니다 두 배입니다.

처음에는 세션을 열 때이를 선언 했음에도 불구하고이 인터셉터가 작동하지 않는 것처럼 보였습니다. 둘째로 나는 완전히 짖고 완전히 작동하지 않습니다.

+0

이렇게 작동합니까? – codeulike

+0

전 두렵습니다. 그것은 __awkward__ 데이터베이스 설계를 수용하지 않는 것 같습니다 –

답변

0

첫 번째 질문에 대해 말씀 드릴 수 있습니다. 세션을 열 때 인터셉터를 지나가고 있습니까?

config.SetInterceptor(new yourInteceptor()); 

......... 

if (config.Interceptor != null) 
{ 
    session = factory.OpenSession(config.Interceptor); 
} 
    else 
{  
    session = factory.OpenSession(); 
} 
관련 문제