示例#1
0
        /// <summary>
        /// Processes all rows of a query with nested results
        /// </summary>
        /// <param name="mappedProperty">the created child objects will be assigned to the property as array</param>
        /// <param name="mappedQuery">mapped query object</param>
        /// <param name="reader">current reader</param>
        /// <param name="jsonWriter">current json writer</param>
        /// <param name="rowFinishedAction">action will be fired when the rowset for one object (idColumn equals) was read</param>
        public void ProcessResults(MappedProperty mappedProperty, MappedQuery mappedQuery, IDataReader reader, JsonTextWriter jsonWriter, Action <IDictionary <string, object>, RowSet, List <string> > rowFinishedAction)
        {
            var           arrayWriter            = new ConditionalJsonArrayWriter(jsonWriter, mappedProperty);
            List <string> fieldNameList          = null;
            var           queryWithNestedResults = mappedQuery as MappedQueryWithNestedResults;
            var           currentRowSet          = new RowSet(queryWithNestedResults.IdColumn, new List <IDictionary <string, object> >());
            IDictionary <string, object> lastRow = null;
            var lookUpTable = reader.GetFieldIndexLookupTable();

            while (reader.Read())
            {
                arrayWriter.StartArray();
                fieldNameList = fieldNameList == null?reader.GetFieldNameList() : fieldNameList;

                var currentRow = reader.ToDictionary(lookUpTable);
                if (lastRow != null && !Object.Equals(lastRow[queryWithNestedResults.IdColumn], currentRow[queryWithNestedResults.IdColumn]))
                {
                    rowFinishedAction(lastRow, currentRowSet, fieldNameList);
                    currentRowSet = new RowSet(queryWithNestedResults.IdColumn, new List <IDictionary <string, object> >());
                }
                currentRowSet.Rows.Add(currentRow);
                lastRow = currentRow;
            }
            if (currentRowSet.Rows.Count > 0)
            {
                rowFinishedAction(lastRow, currentRowSet, fieldNameList);
            }
            arrayWriter.EndArray();
        }
示例#2
0
        public static IQuery <ICollection <Target> > Project <Model, Target>(this IQuery <ODataFeed <Model> > modelQuery, Expression <Func <Model, Target> > mapExpr)
            where Model : ODataObject
        {
            IQuery <ODataFeed <Model> >   modifiedQuery = ApplySelectsAndExpands(modelQuery, mapExpr);
            Query <ICollection <Target> > mappedQuery   = new MappedQuery <ODataFeed <Model>, ICollection <Target> >(modifiedQuery as Query <ODataFeed <Model> >, feed => feed.Feed.Select(mapExpr.Compile()).ToList());

            return(mappedQuery);
        }
示例#3
0
        public static IQuery <Target> Project <Model, Target>(this IQuery <Model> modelQuery, Expression <Func <Model, Target> > mapExpr)
            where Model : ODataObject
            where Target : class
        {
            IQuery <Model> modifiedQuery = ApplySelectsAndExpands(modelQuery, mapExpr);
            Query <Target> mappedQuery   = new MappedQuery <Model, Target>(modifiedQuery as Query <Model>, mapExpr.Compile());

            return(mappedQuery);
        }
        internal static MappedQuery CompileQuery(QueryDefinition queryMapping)
        {
            if (queryMapping == null)
            {
                throw new ArgumentNullException("queryMapping cant be null");
            }
            MappedQuery newMappedQuery = new MappedQuery(queryMapping.Query);
            var         template       = queryMapping.Template;

            CompileProperties(template, newMappedQuery, queryMapping);
            return(newMappedQuery);
        }
        /// <summary>
        /// Processes all rows of a query result
        /// </summary>
        /// <param name="mappedProperty">the created child objects will be assigned to the property as array</param>
        /// <param name="mappedQuery">mapped query object</param>
        /// <param name="reader">current reader</param>
        /// <param name="jsonWriter">current json writer</param>
        /// <param name="rowFinishedAction">action will be fired when the row was read (rowSet is always null)</param>
        public void ProcessResults(MappedProperty mappedProperty, MappedQuery mappedQuery, IDataReader reader, JsonTextWriter jsonWriter, Action <IDictionary <string, object>, RowSet, List <string> > rowFinishedAction)
        {
            var           arrayWriter   = new ConditionalJsonArrayWriter(jsonWriter, mappedProperty);
            List <string> fieldNameList = null;

            while (reader.Read())
            {
                arrayWriter.StartArray();
                fieldNameList = fieldNameList == null?reader.GetFieldNameList() : fieldNameList;

                rowFinishedAction(reader.ToDictionary(), null, fieldNameList);
            }
            arrayWriter.EndArray();
        }
示例#6
0
        internal void WriteQueryResults(MappedQuery query, JsonTextWriter jsonWriter, ParentObject parentObject, IDictionary <string, object> context, MappedProperty mappedProperty)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query cant be null");
            }
            if (jsonWriter == null)
            {
                throw new ArgumentNullException("jsonWriter cant be null");
            }
            var command = commandManager.GetCommandForQuery(query);

            using (var reader = command.Prepare(parentObject, context).ExecuteReader())
            {
                standardQueryResultProcessor.ProcessResults(mappedProperty, query, reader, jsonWriter, (c, r, l) => WriteJsonObject(query, jsonWriter, c, null, l, parentObject, context));
            }
        }
示例#7
0
        public IJsonMappingBuilder Query(string propertyName, string query, Action <IJsonMappingBuilder> config)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName cant be null");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query cant be null");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config cant be null");
            }
            var builder     = new JsonMappingBuilder(this);
            var mappedQuery = new MappedQuery(query);

            builder.Result = mappedQuery;
            Result.MappedPropertyList.Add(new MappedProperty(propertyName, mappedQuery));
            config(builder);
            return(this);
        }
示例#8
0
 /// <summary>
 /// Gets the prepared command for the provided mapped query
 /// </summary>
 /// <param name="query">current mapped query</param>
 /// <returns></returns>
 public ICommandWithParameterSetter GetCommandForQuery(MappedQuery query)
 {
     return(queryCommands[query]);
 }