简体   繁体   English

如何在LINQ中将两个查询联合到流畅的NHibernate?

[英]How to Union two Queries in LINQ to Fluent NHibernate?

How to Union two Queries in LINQ to Fluent NHibernate? 如何在LINQ中将两个查询联合到流畅的NHibernate?

They return the same type but the queries are over separate entities: 它们返回相同的类型,但查询位于不同的实体上:

IQueryable<Event> eventQuery1 = session.Query<Event>().Where(e => e.EventType.Id == eventTypeId);

IQueryable<Event> eventQuery2 = session.Query<Nomination>().Select(n => n.Event).Distinct();

I tried the Union() and Concat() methods but they failed: 我尝试了Union()和Concat()方法但是它们失败了:

eventQuery1 = eventQuery1.Union(eventQuery2);

The UnionResultOperator result operator is not current supported

I don't want to load the objects from database then apply the concat, I'd like it to be done before the objects are returned from database so that I can apply some Fetches on the final list from the union. 我不想从数据库加载对象然后应用concat,我希望在从数据库返回对象之前完成它,以便我可以在union的最终列表中应用一些Fetches。

Not sure if it works with NHibernate LINQ, but a work-around is: 不确定它是否适用于NHibernate LINQ,但解决方法是:

IQueryable<Event> eventQuery =
     session.Query<Event>()
            .Where(e => e.EventType.Id == eventTypeId
                     || session.Query<Nomination>()
                               .Select(n => n.Event.Id)
                               .Contains(e.Id))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM