Beispiel #1
0
        private IList ExecuteOe <T, TResult>(LambdaExpression lambda)
        {
            Container  container = CreateContainer();
            IQueryable query     = GetQuerableOe <T>(container);
            var        visitor   = new TypeMapperVisitor(query)
            {
                TypeMap = t => Type.GetType("ODataClient." + t.FullName)
            };
            var call = visitor.Visit(lambda.Body);

            Type elementType;
            ExecuteQueryFunc <Object> func;

            if (call.Type.GetTypeInfo().IsGenericType)
            {
                elementType = call.Type.GetGenericArguments()[0];
                func        = ExecuteQuery <Object>;
            }
            else
            {
                elementType = typeof(Object);
                func        = ExecuteQueryScalar <Object>;
            }

            IList fromOe = CreateDelegate(elementType, func)(query, call);

            TestHelper.SetNullCollection(fromOe, GetIncludes(lambda));

            if (typeof(TResult) == typeof(Object))
            {
                fromOe = TestHelper.SortProperty(fromOe);
            }
            return(fromOe);
        }
Beispiel #2
0
        public async Task <IList> ExecuteOe <TResult>(String requestUri, Type baseEntityType)
        {
            var parser = new OeParser(new Uri("http://dummy/"), OeDataAdapter, EdmModel);
            var stream = new MemoryStream();
            await parser.ExecuteQueryAsync(ParseUri(requestUri), OeRequestHeaders.Default, stream, CancellationToken.None);

            stream.Position = 0;

            var   reader = new ResponseReader(EdmModel, DbDataAdapter.EntitySetMetaAdapters);
            IList fromOe;

            if (typeof(TResult) == typeof(Object))
            {
                IEnumerable <JObject> jobjects = reader.ReadOpenType(stream, baseEntityType).Select(t => JRawToEnum(t)).ToList();
                fromOe = TestHelper.SortProperty(jobjects);
            }
            else if (typeof(TResult).GetTypeInfo().IsPrimitive)
            {
                fromOe = new String[] { new StreamReader(stream).ReadToEnd() }
            }
            ;
            else
            {
                fromOe = reader.ReadFeed <TResult>(stream).ToList();
            }

            return(fromOe);
        }