1
我有一個應用程序,我試圖實現DDD的概念。我有我的存儲庫類與一些方法列出實體。我想知道我該怎麼辦查詢與QueryOver過濾與AND
操作,當參數被填滿,樣品Dynamic Query Queryover的條件
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查詢字符串? hehehe
謝謝!
是的,我知道我可以做第二種方式,我怎樣才能添加其他可能的條件它? –
@felipeoriani閱讀了謂詞構建器,假設你對第三方庫很熟悉(很多人使用它,這是安全的;-),那麼我會使用它。 – Faraday
偉大的代碼,我會嘗試,謝謝:))...我不知道這個庫,我在哪裏可以找到它?謝謝[] s –