Beispiel #1
0
            public AsyncTypeAwaitable FirstOrDefaultAsync(QueryAdapterBase queryAdapter, IQueryable source, CancellationToken cancellation)
            {
                if (source is not IQueryable <T> typedQueryable)
                {
                    typedQueryable = source.Cast <T>();
                }

                var task = queryAdapter.FirstOrDefaultAsync(typedQueryable, cancellation);

                return(task.AsTypeAwaitable());
            }
Beispiel #2
0
            public AsyncTypeAwaitable FirstOrDefaultAsync(
                QueryAdapterBase queryAdapter,
                IQueryable source,
                Expression predicate,
                CancellationToken cancellation)
            {
                if (source is not IQueryable <T> typedQueryable)
                {
                    typedQueryable = source.Cast <T>();
                }

                if (predicate is UnaryExpression unaryExpression && unaryExpression.NodeType == ExpressionType.Quote)
                {
                    predicate = unaryExpression.Operand;
                }

                // TODO: Can we convert the selector if it is not of the appropriate type?
                var task = queryAdapter.FirstOrDefaultAsync(typedQueryable, (Expression <Func <T, bool> >)predicate, cancellation);

                return(task.AsTypeAwaitable());
            }