0
我正在查詢兩個不同的表。 在第一個查詢中,我得到一些Ids,然後我必須在另一個表中檢查。 然後我再次用第二個查詢的結果做第一個查詢。簡化多個nhibernate查詢
這不能是這樣做的最好方法。
但我還沒有找到一個好方法來解決它。所以一些幫助將不勝感激。
IntOrderInvoiceCostOut y = null;
var list = session.QueryOver<IntOrderInvoiceCostOut>(() => y)
.Where(x => x.IntegrationHandleDate == null)
.Select(Projections.Distinct(Projections.Property(() => y.Externalid)))
.List<string>();
var nonPreliminaryOrders = session.QueryOver<RefImplOrderEntity>()
.WhereRestrictionOn(x => x.ExternalId).IsIn(list.ToList())
.Where(x => x.StatusTypeId != 95)
.Select(x => x.ExternalId)
.List<string>();
var finalList = session.QueryOver<IntOrderInvoiceCostOut>()
.WhereRestrictionOn(x => x.Externalid).IsIn(nonPreliminaryOrders.ToList())
.Where(x => x.IntegrationHandleDate == null)
.OrderBy(x => x.IntegrationCreateDate)
.Asc
.List();
該代碼工作...但我真的很醜。
我不記得了我的頭頂,但你應該能夠使用子查詢做到這一點。 http://www.andrewwhitaker.com/blog/2014/10/24/queryover-series-part-8-working-with-subqueries/ –
你可以使用Linq嗎? –