2008-12-22 12 views
19

NHibernate के लिए मानदंड बनाते समय सभी मानदंड AND के रूप में जोड़े जाते हैं।एनएचबीरनेट के लिए या स्टेटमेंट कैसे बनाएं?

उदाहरण के लिए:

session.CreateCriteria(typeof(someobject)) 
.Add(critiera) 
.Add(other_criteria) 

तो अंत परिणाम होगा

SELECT ... 
FROM ... 
WHERE criteria **AND** other_criteria 

मैं NHibernate बताने के लिए के रूप में criterias जोड़ने के लिए "या"

SELECT ... 
FROM ... 
WHERE criteria **OR** other_criteria 

किसी भी मदद की है चाहते हैं सराहना

उत्तर

48

आप Conjunction और Disjunction कक्षाओं की तलाश में हैं, इनका उपयोग विभिन्न विवरणों को OR और AND कथन बनाने के लिए किया जा सकता है।

और

.Add(
    Expression.Conjunction() 
    .Add(criteria) 
    .Add(other_criteria) 
) 

या

.Add(
    Expression.Disjunction() 
    .Add(criteria) 
    .Add(other_criteria) 
) 
2

session.CreateCriteria(typeof(someobject)) 
    .Add(critiera) 
    .Add(other_criteria); 

जहां:

other_criteria = Restrictions.or("property", "value"); 

आप Criteria Interface documentation of Hibernate, जो NHibernate रूप में ही है के बाद इस बारे में अधिक सीख सकते हैं आप Restrictions.or, ऐसी है कि इस्तेमाल कर सकते हैं।

13

उपयोग Restrictions.Disjunction()

 var re1 = Restrictions.Eq(prop1, prop_value1); 
     var re2 = Restrictions.Eq(prop2, prop_value2); 
     var re3 = Restrictions.Eq(prop3, prop_value3); 

     var or = Restrictions.Disjunction(); 
     or.Add(re1).Add(re2).Add(re3); 

     criteria.Add(or); 
संबंधित मुद्दे