示例#1
0
        public IEnumerable <TProjection> Query <TBase, TProjection>(IDbConnection connection, IDbTransaction transaction, ProjectedSelectQuery <TBase, TProjection> query)
            where TBase : class, new()
        {
            var sqlResult = this.selectWriter.GenerateSql(query);

            if (sqlResult.FetchTree.Children.Count == 0)
            {
                return(connection.Query <TBase>(sqlResult.Sql, sqlResult.Parameters, transaction)
                       .Select(query.ProjectionExpression.Compile()));
            }

            var projectionExpressionRewriter = new ProjectionExpressionRewriter <TBase, TProjection>(this.configuration, query, sqlResult.FetchTree);
            var projectionDelegateResult     = projectionExpressionRewriter.Rewrite();

            return(connection.Query <TProjection>(sqlResult.Sql, projectionDelegateResult.Types, projectionDelegateResult.Mapper, sqlResult.Parameters, transaction, splitOn: sqlResult.FetchTree.SplitOn));
        }
示例#2
0
        private void AssertMapperMatches <TBase, TProjection>(object[] inputs, Type[] types, IProjectedSelectQuery <TBase, TProjection> projectedSelectQuery, params Action <TProjection>[] assertions)
            where TBase : class, new()
        {
            var selectWriter       = this.GetSql2012Writer();
            var concreteQuery      = (ProjectedSelectQuery <TBase, TProjection>)projectedSelectQuery;
            var sqlResult          = selectWriter.GenerateSql(concreteQuery);
            var projectionRewriter = new ProjectionExpressionRewriter <TBase, TProjection>(selectWriter.Configuration, concreteQuery, sqlResult.FetchTree);
            var result             = projectionRewriter.Rewrite();

            Assert.Equal(types, result.Types);
            var projection = result.Mapper(inputs);

            foreach (var assertion in assertions)
            {
                assertion(projection);
            }
        }