日付情報を含む特定のインターフェイスを実装するX個のエンティティの論理和を使用して、特定の数のOR条件を追加しようとしています。私の問題は、SQLが生成されるときに、すべての論理和条件がQueryOverのルートエンティティを指すことです。
条件を追加するためのジェネリックメソッドを作成しました
public static QueryOver<T,T2> AddChangedCondition<T,T2>(this QueryOver<T,T2> query, DateTime from, DateTime to, Disjunction disjunction) where T2 : IHaveDate
{
if(disjunction == null )
disjunction = new Disjunction();
disjunction.Add<T2>(k => (k.DeleteDate > from && k.DeleteDate < to)
|| k.CreatedDate > from
|| k.UpdatedDate > from);
return query;
}
私はそれをこのように使いたい:
Disjunction disjunction = null;
var query = QueryOver.Of<User>()
.AddChangedCondition(fromDate,toDate, disjunction)
.JoinQueryOver<Program>(user => user.Programs)
.AddChangedCondition(fromDate,toDate, disjunction);
query.Where(disjunction);
これから生成されたSQLは、
select ....
from User
where
(
(
this_.raderadDatum > @p1
and this_.raderadDatum < @p2
)
or this_.skapadDatum > @p3
or this_.uppdateradDatum > @p4
)
or
(
this_.raderadDatum > @p1
and this_.raderadDatum < @p2
)
or this_.skapadDatum > @p3
or this_.uppdateradDatum > @p4
)
エイリアスを使用してさまざまなソリューションを試しましたが、成功しませんでした。どんな助けにも素晴らしいでしょう!