0

使用Linq的Union方法,配合Entity Framework,在同一个上可以使用的次数有上限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;
}

IQueryables我可以使用 Entity 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 回答