休眠条件

bha*_*rat 1 nhibernate

我想在 nHibernate 中生成一个 where 条件,如下所示有人可以帮我吗

选择 Id,Name from Employee where (id=@id or Id is Null) 我希望代码生成 where 条件。

asg*_*las 5

您应该在此处查看文档:http : //nhibernate.info/doc/nh/en/index.html#querycriteria-narrowing

使用标准 API 的解决方案是:

session.CreateCriteria<Employee>()
    .Add(Restrictions.Eq("Id", id) | Restrictions.IsNull(id));
Run Code Online (Sandbox Code Playgroud)