2013-04-12 18 views
0

當使用Linq的Union方法時,使用實體框架,在同一個IQueryable上可以使用的次數是否有上限?Linq2Sql的聯合調用數量是否有限制?

考慮這個片段中,顯然有點做作:

public IQueryable<Person> GetPeople(IEnumerable<PersonDto> candidates) 
{ 
    var successful = this.peopleRepository.All().Where(p => false); 

    foreach(var candidate in candidates) 
    { 
     if (candidate.IsSuccessful()) 
     { 
      var successfulCandidate = this.peopleRepository.All() 
          .Where(p => p.id == candidate.id); 
      successful = successful.Union(successfulCandidate); 
     } 
    } 

    return successful; 
} 

是否有限制次數,我可以聯合IQueryables,仍然可以得到使用實體框架和SQL Server的結果嗎?

+0

呵呵,沒有。你爲什麼認爲它應該? –

回答

0

聯合方法使用==運算符實現第一個參數(此處爲successful)。從MSDN:

The query behavior that occurs as a result of executing an expression tree that 
represents calling Union<TSource>(IQueryable<TSource>, IEnumerable<TSource>) depends 
on the implementation of the type of the source1 parameter. The expected behavior is that 
the set union of the elements in source1 and source2 is returned. 

因此,如果源是一個自定義的對象,你可能有誤差取決於你的實現==,你把你的Union參數是什麼,但它無關的呼叫數量到Union

+0

好的,但是投入EF和SQL Server,它可以處理的調用數量是否有限制? –

+0

我不明白這可能會有什麼不同。在實體上使用'Union'與用手修改集合是相同的事情(對於EF) –

+0

您是否有特別的理由認爲它可能導致問題? –

相關問題