当使用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;
}
我可以使用Entity Framework和SQL Server结合IQueryables
并仍然获得结果的次数是否有限制?
答案 0 :(得分: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