2010-07-29 77 views
0

刪除我有一個LINQ查詢如何提高LINQ查詢,並在第

var query = from record in session.Query<Record>() 
          from brwSet in session.Query<BorrowerSet>() 
          from brw in session.Query<Borrower>() 
          where 
          brw.PrintOrder == 1 && brwSet.PrintOrder == 0 
          && record.Package.BorrowerSet.Contains(brwSet) 
          && brwSet.Borrower.Contains(brw) 
          select new Summary() 
          { 
           BorrowerFirstName = brw.Contact.FirstName, 
           BorrowerLastName = brw.Contact.LastName, 
           LoanPackageID = record.Id 
          }; 

我怎麼能改寫這個以消除多餘的條款

from brwSet in session.Query<BorrowerSet>() 
from brw in session.Query<Borrower>() 

我怎麼能改寫這個讓我不要在這些集合上不需要包含函數?

record.Package.BorrowerSet.Contains(brwSet) && brwSet.Borrower.Contains(brw) 
+0

你想通過這些建議的改變實現什麼?例如你可以用連接來替換2個froms,並將連接條件放在join語句中而不是where子句中,但它會和現有代碼做同樣的事情,所以爲什麼要這麼做。 – 2010-07-29 22:34:17

+0

我想從美學的條款乘坐額外的條款。我更關心的是去除包含調用,因爲這轉換爲SQL中的in子句。 – 2010-07-30 14:33:26

回答

0

此查詢沒有Contains。

var query = 
    from record in session.Query<Record>() 
    from brwSet in record.Package.BorrowerSet 
    where brwSet.PrintOrder == 0 
    from brw is brwSet.Borrowers 
    where brw.PrintOrder == 1 
    select new Summary() 
    { 
    BorrowerFirstName = brw.Contact.FirstName, 
    BorrowerLastName = brw.Contact.LastName, 
    LoanPackageID = record.Id 
    }; 
+0

因爲brwSet.Borrower是借款人的集合,所以這不起作用。 – 2010-07-30 14:31:44

+0

nhibernate 3也似乎不支持「from brwSet in record.Package.BorrowerSet」語句 – 2010-07-30 14:47:04