Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to create criteria for a query but it is not working ? The query is
SELECT * FROM patientdetailinformationview where (patientid=101 and PatientCaseId=1316) or (patientid=105 and Case_type=1)

Please guide in this regard. Thanks in advance
Posted

1 solution

You need to have two separate conjunctions added to a single disjunction. Something like:

C#
var conjunction1 = Restrictions.Conjunction();
conjunction1.Add(Restrictions.Eq("patientid", 101));
conjunction1.Add(Restrictions.Eq("PatientCaseId", 1316));

var conjunction2 = Restrictions.Conjunction();
conjunction2.Add(Restrictions.Eq("patientid", 105));
conjunction2.Add(Restrictions.Eq("Case_type", 1));

var orDisjunction = Restrictions.Disjunction();

orDisjunction.Add(conjunction1);
orDisjunction.Add(conjunction2);

return session.CreateCriteria(typeof(PatientDetailInformation))
                .Add(orDisjunction)
                .List<PatientDetailInformation>()
                .ToList();


Hope it helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900