Nhibernate ICRITERIA syntax

1.4k views Asked by At

I have the following sql :

       Select * from table where (Field1=1 and Field2=1) or (Field3=1)

How do i create the selection using NHibernate ICriteria Regards Keld

1

There are 1 answers

1
harriyott On

Use Restrictions.Or and Restrictions.And

Session
.CreateCriteria<Table>()
.Add(Restrictions.Or(
    Restrictions.And(
        Restrictions.Eq("Field1", 1),
        Restrictions.Eq("Field2", 1)),
    Restrictions.Eq("Field3", 1))
.List<Table>();