/// <summary> /// Adds the future query to the waiting queries list on this context. /// </summary> /// <param name="query">The future query.</param> public void AddQuery(IFutureQuery query) { if (query == null) { throw new ArgumentNullException("query"); } FutureQueries.Add(query); }
/// <summary> /// Gets the data command for this query. /// </summary> /// <param name="dataContext">The data context to get the command from.</param> /// <returns>The requested command object.</returns> protected override DbCommand GetCommand(System.Data.Linq.DataContext dataContext) { IFutureQuery futureQuery = this; var source = futureQuery.Query; // get static count method FindCountMethod(); // create count expression var genericCount = _countMethod.MakeGenericMethod(new[] { source.ElementType }); var expression = Expression.Call(null, genericCount, source.Expression); return(dataContext.GetCommand(expression)); }
/// <summary> /// Sets the underling value after the query has been executed. /// </summary> /// <param name="dataContext">The data context to translate the results with.</param> /// <param name="reader">The <see cref="DbDataReader" /> to get the result from.</param> protected virtual void SetResult(ObjectContext dataContext, DbDataReader reader) { IsLoaded = true; try { IFutureQuery futureQuery = this; var source = futureQuery.Query; var q = source as ObjectQuery; if (q == null) { throw new InvalidOperationException("The future query is not of type ObjectQuery."); } // create execution plan dynamic queryProxy = new DynamicProxy(q); // ObjectQueryState dynamic queryState = queryProxy.QueryState; // ObjectQueryExecutionPlan dynamic executionPlan = queryState.GetExecutionPlan(null); // ShaperFactory dynamic shaperFactory = executionPlan.ResultShaperFactory; // Shaper<T> dynamic shaper = shaperFactory.Create(reader, dataContext, dataContext.MetadataWorkspace, MergeOption.AppendOnly, false, true, false); var list = new List <T>(); IEnumerator <T> enumerator = shaper.GetEnumerator(); while (enumerator.MoveNext()) { list.Add(enumerator.Current); } _result = list; // translate has issue with column names not matching //var resultSet = dataContext.Translate<T>(reader); //_result = resultSet.ToList(); } catch (Exception ex) { Exception = ex; } }
/// <summary> /// Sets the underling value after the query has been executed. /// </summary> /// <param name="dataContext">The data context to translate the results with.</param> /// <param name="reader">The <see cref="DbDataReader" /> to get the result from.</param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="InvalidOperationException">The future query is not of type ObjectQuery.</exception> protected virtual async Task SetResultAsync(ObjectContext dataContext, DbDataReader reader, CancellationToken cancellationToken = default(CancellationToken)) { _isLoaded = true; try { IFutureQuery futureQuery = this; var source = futureQuery.Query; var q = source as ObjectQuery; if (q == null) { throw new InvalidOperationException("The future query is not of type ObjectQuery."); } // create execution plan dynamic queryProxy = new DynamicProxy(q); // ObjectQueryState dynamic queryState = queryProxy.QueryState; // ObjectQueryExecutionPlan dynamic executionPlan = queryState.GetExecutionPlan(null); // ShaperFactory dynamic shaperFactory = executionPlan.ResultShaperFactory; // Shaper<T> dynamic shaper = shaperFactory.Create(reader, dataContext, dataContext.MetadataWorkspace, MergeOption.AppendOnly, false, true, false); var list = new List <T>(); // Shaper<T> GetEnumerator method return IDbEnumerator<T>, which implements publicly accessible IDbAsyncEnumerator<T> IDbAsyncEnumerator <T> enumerator = shaper.GetEnumerator(); while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false)) { list.Add(enumerator.Current); } _result = list; // translate has issue with column names not matching //var resultSet = dataContext.Translate<T>(reader); //_result = resultSet.ToList(); } catch (Exception ex) { Exception = ex; } }
/// <summary> /// Gets the data command for this query. /// </summary> /// <param name="dataContext">The data context to get the command from.</param> /// <returns>The requested command object.</returns> protected virtual FuturePlan GetPlan(ObjectContext dataContext) { IFutureQuery futureQuery = this; var source = futureQuery.Query; var q = source as ObjectQuery; if (q == null) { throw new InvalidOperationException("The future query is not of type ObjectQuery."); } var plan = new FuturePlan { CommandText = q.ToTraceString(), Parameters = q.Parameters }; return(plan); }
/// <summary> /// Adds the future query to the waiting queries list on this context. /// </summary> /// <param name="query">The future query.</param> public void AddQuery(IFutureQuery query) { if (query == null) throw new ArgumentNullException("query"); FutureQueries.Add(query); }