0

Entity FrameworkでLinqのUnionメソッドを使用する場合、同一での使用回数に上限はありIQueryableますか?

このスニペットを考えてみてください。明らかに少し不自然です。

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;
}

IQueryablesEntity Framework と SQL Server を使用してユニオンを作成し、結果を取得できる回数に制限はありますか?

4

1 に答える 1

0

Union メソッドは==、最初のパラメーター (ここでは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

于 2013-04-12T07:30:11.373 に答える