我有一个应用程序,我正在尝试实现 DDD 概念。我的存储库类有一些列出实体的方法。我想知道如何使用 QueryOver 进行查询以使用AND
运算符过滤分离,当参数填充时,示例
public IEnumerable<Product> FindProducts(string name, decimal? price, DateTime? validDate, int? stock, int? idSupplier)
{
var query = Session.QueryOver<Product>().OrderBy(x => x.Name).Asc;
if (!string.IsNullOrEmpty(name))
// add where condition for name parameter
if (price.HasValue)
// add 'AND' where condition for price parameter
if (validDate.HasValue)
// add 'AND' where condition for validDate parameter
if (idSupplier.HasValue)
// add 'AND' where condition for idSupplier parameter
// other possible conditions
return query.List();
}
在我使用 HQL 字符串查询之前有什么办法吗?呵呵呵呵
谢谢!