示例#1
0
        /// <summary>
        /// The problem: we want to cache queries, but the StructuredQueries contain GUIDs that vary from call to call.
        /// The CachingQuerySqlBuilderKey happily handles this via StructuredQuery.CacheKeyToken. However, the result contains
        /// references back to the original query. And stuff down stream relies on having the correct GUIDs in the referenced columns.
        /// The solution: we take a shallowing copy of the result, and substutite in the columns from our current query.
        /// </summary>
        internal static QueryBuild MutateResultToMatchCurrentQuery(QueryBuild queryBuild, StructuredQuery originalQuery, StructuredQuery currentQuery)
        {
            if (queryBuild == null)
            {
                throw new ArgumentNullException("queryBuild");
            }
            if (originalQuery == null)
            {
                throw new ArgumentNullException("originalQuery");
            }
            if (currentQuery == null)
            {
                throw new ArgumentNullException("currentQuery");
            }

            // Clone result
            QueryBuild result = queryBuild.ShallowClone();

            result.Columns          = MutateColumnList(result.Columns, originalQuery.SelectColumns, currentQuery.SelectColumns);
            result.AggregateColumns = MutateColumnList(result.AggregateColumns, originalQuery.SelectColumns, currentQuery.SelectColumns);
            return(result);
        }