我有一个实体的客户NHibernate的:通过例如在主键查询产生 “WHERE(1 = 1)”
public class Customer
{
public virtual int ID { get; set; }
public virtual string Firstname { get; set; }
public virtual string Lastname { get; set; }
}
和我的DAL方法是:
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;
}
但问题是当我打电话给我这样的方法
var exemple = new Customer() { ID = 2 };
var customers = provider.GetCustomers(exemple);
我有我的所有客户在数据库中的集合,因为NHibernate生成以下SQL查询
NHibernate: SELECT this_.CustomerId as CustomerId0_0_, this_.Firstname as Firstname0_0_, this_.Lastname as Lastname0_0_ FROM Customers this_ WHERE (1=1)
NHibernate支持主键上的QBE? 我在做什么错?
P.S.我忘记提及我使用的NHibernate版本。它是2.0.1.GA.