NHibernate v3.2.0 と次のクエリに問題があります。
class DocumentBase {}
class Requisition: DocumentBase {}
class Order: DocumentBase {}
Repository.GetAll<DocumentBase>()
.Where(d => (d is Requisition) && ((Requisition)d).ProductItem != null)
基本クエリはすべてのドキュメントを一覧表示するように設計されていますが、このドキュメントをタイプ (および製品のないドキュメントなどの準タイプ) でフィルタリングすることもできます。上記のコードには条件が 1 つしかありませんが、述語はより複雑になる可能性があります。たとえば、次のようになります。
Repository.GetAll<DocumentBase>()
.Where(d =>
((d is Requisition) && ((Requisition)d).ProductItem != null) ||
(d is Order) ||
[...]
)
InvalidPathException
実行すると、メッセージで受け取りますInvalid path: 'd.ProductItem'
。何か案は?サポートされていますか?
これまでのところ、次のクエリでこのエラーを回避できました。
Repository.GetAll<DocumentBase>()
.Where(d =>
(d is Requisition) &&
Repository.GetAll<Requisition>()
.Any(r => r.Id == d.Id && r.ProductItem != null)
)
しかし、間違いなく、パフォーマンスの点で最良の選択ではありません。