如何在QueryOver中添加可选的where子句?
TL; DR
我正在尝试为应用程序实现搜索表单并使用QueryOver 一些搜索参数是可选的。
var query =
myDatabase.QueryOver(() => customerAlias)
.JoinAlias(() => customerAlias.Projects, () => projectAlias)
.Where(() => projectAlias.IsClosed >= 1)
... possibly add more stuff
答案 0 :(得分:4)
QueryOver
在执行中被推迟。它只会在您通过调用.List<T>()
。
var query =
myDatabase.QueryOver(() => customerAlias)
.JoinAlias(() => customerAlias.Projects, () => projectAlias)
.Where(() => projectAlias.IsClosed >= 1);
if (myCondition) {
query = query.Where(...);
}
var result = query.List<T>(); //Or however else you want to make it execute.
您仍然可以通过这种方式访问内联别名。