QueryableExtensions.AnyAsync<TSource> 方法 (IQueryable<TSource>, Expression<Func<TSource, Boolean>>, CancellationToken)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]
异步确定序列的任何元素是否满足条件。
命名空间: System.Data.Entity
程序集: EntityFramework(在 EntityFramework.dll 中)
语法
声明
<ExtensionAttribute> _
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Shared Function AnyAsync(Of TSource) ( _
source As IQueryable(Of TSource), _
predicate As Expression(Of Func(Of TSource, Boolean)), _
cancellationToken As CancellationToken _
) As Task(Of Boolean)
用法
Dim source As IQueryable(Of TSource)
Dim predicate As Expression(Of Func(Of TSource, Boolean))
Dim cancellationToken As CancellationToken
Dim returnValue As Task(Of Boolean)
returnValue = source.AnyAsync(predicate, _
cancellationToken)
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<bool> AnyAsync<TSource>(
this IQueryable<TSource> source,
Expression<Func<TSource, bool>> predicate,
CancellationToken cancellationToken
)
[ExtensionAttribute]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TSource>
static Task<bool>^ AnyAsync(
IQueryable<TSource>^ source,
Expression<Func<TSource, bool>^>^ predicate,
CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
static member AnyAsync :
source:IQueryable<'TSource> *
predicate:Expression<Func<'TSource, bool>> *
cancellationToken:CancellationToken -> Task<bool>
JScript does not support generic types and methods.
类型参数
- TSource
source 的元素的类型。
参数
- source
类型:System.Linq.IQueryable<TSource>
要测试其元素是否满足某个条件的 IQueryable<T>。
- predicate
类型:System.Linq.Expressions.Expression<Func<TSource, Boolean>>
用于测试每个元素是否满足条件的函数。
- cancellationToken
类型:System.Threading.CancellationToken
等待任务完成期间要观察的 CancellationToken。
返回值
类型:System.Threading.Tasks.Task<Boolean>
表示异步操作的任务。如果源序列的任何元素通过指定谓词中的测试,则任务结果包含 true;否则包含 false。
使用说明
在 Visual Basic 和 C# 中,可以在 IQueryable<TSource> 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。有关详细信息,请参阅https://msdn.microsoft.com/zh-cn/library/bb384936(v=vs.113)或https://msdn.microsoft.com/zh-cn/library/bb383977(v=vs.113)。
异常
例外 | 条件 |
---|---|
ArgumentNullException | source 或 predicate 为 null。 |
InvalidOperationException | source 不实现 IDbAsyncQueryProvider。 |
备注
不支持对同一上下文实例执行多个活动操作。 使用“await”以确保在对此上下文调用另一个方法前完成了所有异步操作。