public IEnumerable <Dictionary <String, Object> > Resolve(ResolveFieldContext context) { var results = new List <Dictionary <String, Object> >(); var translator = new OeGraphqlAstToODataUri(_edmModel, context); ODataUri odataUri = translator.Translate(context.Document.OriginalQuery); IEdmModel refModel = _edmModel.GetEdmModel(odataUri.Path); Db.OeDataAdapter dataAdapter = refModel.GetDataAdapter(refModel.EntityContainer); context.UserContext = dataAdapter.CreateDataContext(); try { var queryContext = new Parsers.OeQueryContext(refModel, odataUri); IAsyncEnumerator <Object> asyncEnumerator = dataAdapter.Execute(context.UserContext, queryContext).GetEnumerator(); using (var entityAsyncEnumerator = new OeGraphqlAsyncEnumerator(asyncEnumerator, queryContext.EntryFactory)) { while (entityAsyncEnumerator.MoveNext().GetAwaiter().GetResult()) { results.Add(entityAsyncEnumerator.Current); } } } finally { if (context.UserContext != null) { dataAdapter.CloseDataContext(context.UserContext); } } return(results); }
private IAsyncEnumerable <Object> ExecuteGet(IEdmModel refModel, ODataUri odataUri, OeRequestHeaders headers, IQueryable source) { if (_modelBoundProvider != null) { _modelBoundProvider.Validate(_edmModel, odataUri); } _queryContext = new OeQueryContext(refModel, odataUri) { MetadataLevel = headers.MetadataLevel }; if (odataUri.Path.LastSegment is OperationSegment) { return(OeOperationHelper.ApplyBoundFunction(_queryContext)); } if (source != null) { _queryContext.QueryableSource = e => e == _queryContext.EntryFactory.EntitySet ? source : null; } if (_queryContext.ODataUri.Path.LastSegment is CountSegment) { headers.ResponseContentType = OeRequestHeaders.TextDefault.ContentType; int count = _dataAdapter.ExecuteScalar <int>(_dataContext, _queryContext); return((IAsyncEnumerable <Object>)Infrastructure.AsyncEnumeratorHelper.ToAsyncEnumerable(Task.FromResult(count))); } return(_dataAdapter.Execute(_dataContext, _queryContext)); }
public async Task ExecuteAsync(ODataUri odataUri, OeRequestHeaders headers, Stream stream, CancellationToken cancellationToken) { if (_modelBoundProvider != null) { _modelBoundProvider.Validate(_edmModel, odataUri); } var queryContext = new OeQueryContext(_edmModel, odataUri) { MetadataLevel = headers.MetadataLevel }; if (queryContext.ODataUri.Path.LastSegment is OperationSegment) { using (IAsyncEnumerator <Object> asyncEnumerator = OeOperationHelper.ApplyBoundFunction(queryContext).GetEnumerator()) await Writers.OeGetWriter.SerializeAsync(queryContext, asyncEnumerator, headers.ContentType, stream, cancellationToken).ConfigureAwait(false); return; } Object dataContext = null; Db.OeDataAdapter dataAdapter = queryContext.EdmModel.GetDataAdapter(queryContext.EdmModel.EntityContainer); try { dataContext = dataAdapter.CreateDataContext(); if (odataUri.Path.LastSegment is CountSegment) { headers.ResponseContentType = OeRequestHeaders.TextDefault.ContentType; int count = dataAdapter.ExecuteScalar <int>(dataContext, queryContext); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(count.ToString(CultureInfo.InvariantCulture)); stream.Write(buffer, 0, buffer.Length); } else { using (IAsyncEnumerator <Object> asyncEnumerator = dataAdapter.Execute(dataContext, queryContext).GetEnumerator()) await Writers.OeGetWriter.SerializeAsync(queryContext, asyncEnumerator, headers.ContentType, stream, cancellationToken).ConfigureAwait(false); } } finally { if (dataContext != null) { dataAdapter.CloseDataContext(dataContext); } } }
public async Task <IEnumerable <Dictionary <String, Object?> > > Resolve(IResolveFieldContext context) { var results = new List <Dictionary <String, Object?> >(); var translator = new OeGraphqlAstToODataUri(_edmModel, context); ODataUri odataUri = translator.Translate(context.Document.OriginalQuery); IEdmModel refModel = _edmModel.GetEdmModel(odataUri.Path); Db.OeDataAdapter dataAdapter = refModel.GetDataAdapter(refModel.EntityContainer); Object dataContext = dataAdapter.CreateDataContext(); OeGraphqlAsyncEnumerator?entityAsyncEnumerator = null; try { var queryContext = new Parsers.OeQueryContext(refModel, odataUri); IAsyncEnumerator <Object> asyncEnumerator = dataAdapter.Execute(dataContext, queryContext).GetAsyncEnumerator(); if (queryContext.EntryFactory == null) { throw new InvalidOperationException("queryContext.EntryFactory must be not null"); } entityAsyncEnumerator = new OeGraphqlAsyncEnumerator(asyncEnumerator, queryContext.EntryFactory, CancellationToken.None); while (await entityAsyncEnumerator.MoveNextAsync()) { if (entityAsyncEnumerator.Current != null) { results.Add(entityAsyncEnumerator.Current); } } } finally { if (dataContext != null) { dataAdapter.CloseDataContext(dataContext); } if (entityAsyncEnumerator != null) { await entityAsyncEnumerator.DisposeAsync().ConfigureAwait(false); } } return(results); }