2009-12-23 4 views
0

다른 개체와 많은 연관이있는 개체가 있습니다. 이것들은 모두 거의 모든 경우에 좋은 nHibernate에 의해 느슨하게 가져옵니다.한 번에 nHibernate ICriteria의 모든 연결에 대해 Fetchmode를 어떻게 설정합니까?

특정 시나리오에서이 경우 많은 레코드를 내보내는 경우 모든 연관에 대해 열망하도록 Fetchmode를 설정하려고합니다. 이 작업을 수행 할 수있는 방법이 수동으로 지정하지 않고도 거기에 각 하나를

ICriteria crit = CreateCriteria(). 
    .SetFetchMode("Address", FetchMode.Eager) 
    .SetFetchMode("ContactPerson", FetchMode.Eager); 

내가 발견하고 싶지만, 할 수 없었던 방법 :

// This doesn't work. 
ICriteria crit = CreateCriteria().SetFetchMode(FetchMode.Eager); 

답변

1

아니,이 담요 방식으로 이것을 할 수있는 방법이 없습니다.

+0

그건 내 두려움 ... 누군가가 나를 틀리게 증명하기를 바랍니다. –

+0

아아아 ... 진실입니다. 필자는 레코드를 하나씩 가져 와서 내보내기에 추가하여 중간에 세션을 플러시하여 다른 접근 방식을 사용했습니다. 이제 서버의 메모리가 더 이상 소모되지 않습니다. 최소한 릴리스를 위해 구현 한 빠른 수정입니다. P –

2

NHibernate 메타 데이터를 사용해 볼 수 있습니다.

ISessionFactory sessionFactory; 

Type type = typeof(MyEntity); 
IClassMetadata meta = sessionFactory.GetClassMetadata(type); 
foreach (string mappedPropertyName in meta.PropertyNames) 
{ 
    IType propertyType = meta.GetPropertyType(mappedPropertyName); 
    if (propertyType.IsAssociationType) 
    { 
     // initialize property 
     // recursively go through the properties of the associated entity 
    } 

    if (propertyType.IsCollectionType) 
    { 
     // initialize collection 
     // if it is a collection of entities, 
     // recursively go through the properties of the associated entity 

     // Use NHibernateUtil.Initialize 
    } 
} 

노력해야 할 지 모르겠습니다.

+0

감사합니다. 나는 sessionfactory에 대한 액세스 권한이없는 수준에서 작업을 수행하고 있으므로이 appraoch가 나에게 도움이 될지 의심 스럽습니다. 하지만 MetaData를 살펴 보겠습니다. –

+0

세션 팩토리를 알고있는 곳에서이 모든 것을 구현하고 다른 부분에 대한 인터페이스로 제공 할 수 있습니다. –

관련 문제