NHibernate: Or-clause with Components
I have two classes:
public class Person{
public virtual string Name { get; set;}
public virtual Address Address { get; set; }
}
public class Address{
public virtual string Street { get; set; }
}
Now I want NHibernate to give me all Persons where Name is equal to "Xyz" or Address.Street is equal to "Xyz".
This approach is an and-conjunction:
ICriteria criteria = session.CreateCriteria(typeof(Person));
criteria.Add(Expressi开发者_运维百科on.Eq("Name", "Xyz"))
.CreateCriteria("Address").Add(Expression.Eq("Street", "Xyz"));
What I want is and or-clause.
Thank you very much! Andy
I've always just used HQL queries for this - much easier to write and read (at least if you're used to SQL. It's something like this:
IQuery query = session.CreateQuery("FROM Person p WHERE p.Name = :Name OR p.Address.Street = :Street");
query.SetParameter("Name", "Xyz");
query.SetParameter("Street", "Xyz");
精彩评论