I have a customer customer
public class Customer { public virtual int ID { get; set; } public virtual string Firstname { get; set; } public virtual string Lastname { get; set; } }
and my DAL method:
public IList<Customer> GetCustomers(Customer example) { var customers = default(IList<Customer>); using (var sessiong = GetSession()) { customers = sessiong.CreateCriteria(typeof(Customer)) .Add(Example.Create(example)) .List<Customer>(); } return customers; }
but the problem is that when I call my method as follows
var exemple = new Customer() { ID = 2 }; var customers = provider.GetCustomers(exemple);
I have a collection of all my clients in the database because NHibernate generates the following SQL query
NHibernate: SELECT this_.CustomerId as CustomerId0_0_, this_.Firstname as Firstname0_0_, this_.Lastname as Lastname0_0_ FROM Customers this_ WHERE (1=1)
Does NHibernate support QBE for primary key? What am I doing wrong?
PS I forgot to mention the version of NHibernate that I use. This is 2.0.1.GA.
source share