3

프로퍼티가 필드에 매핑되는지 알아낼 방법이 있습니까? 나는이 같은 것을 생성하고 싶습니다 "일반 검색과 같은"NHibernate : 프로퍼티가 필드에 매핑되는지 알아보기

string[] words. 
    words = search.Split(' '); 
    Type type = typeof(T); 

    Disjunction disjunction = new Disjunction(); 
    foreach (System.Reflection.PropertyInfo property in type.GetProperties()) 
    { 
     if ((property.PropertyType == typeof(string))) 
     { 

      foreach (string word in words) 
      { 
       disjunction.Add(
        Expression.InsensitiveLike(
         property.Name, 
         "%" + word + "%")); 
      } 
     } 
    } 

나는 검색이 속성을 확인할 수 없습니다 "라는 설명과 함께 NHibernate.QueryException가 발생합니다 NHibernate에 매핑되지 않는 속성을 추가하는 경우 : 텍스트 1은의 : C "

나는 다음과 같은 속성을 매핑하고 있습니다 :

class C 
{  
    [Property(0, Column = "comment")] 
    public virtual string Comment {get; set;} 
} 

답변

4

은 NHibernate에 메타 데이터 API를 사용합니다.

ISessionFactory sessionFactory; 

Type type = typeof(T); 
IClassMetadata meta = sessionFactory.GetClassMetadata(type); 

Disjunction disjunction = new Disjunction(); 
foreach (string mappedPropertyName in meta.PropertyNames) 
{ 
    IType propertyType = meta.GetPropertyType(mappedPropertyName); 

    if (propertyType == NHibernateUtil.String) 
    { 
     foreach (string word in words) 
     { 
      disjunction.Add(
       Expression.InsensitiveLike(
        mappedPropertyName, 
        "%" + word + "%")); 
     } 
    } 
} 
+0

감사합니다. – bernhardrusch