public ProjectionExpressionRewriter(IConfiguration configuration, ProjectedSelectQuery <TBase, TProjection> query, FetchNode rootNode) { this.configuration = configuration; this.query = query; this.rootNode = rootNode; this.fetchNodeLookup = new Dictionary <FetchNode, FetchNodeLookupValue>(); this.parameterExpression = Expression.Parameter(typeof(object[])); }
public SelectWriterResult GenerateSql <TBase, TProjection>(ProjectedSelectQuery <TBase, TProjection> projectedSelectQuery) where TBase : class, new() { // get fetch tree structure var rootNode = this.fetchTreeParser.GetFetchTree(projectedSelectQuery.BaseSelectQuery, out _, out var numberCollectionFetches) ?? new FetchNode(); // add in the projection struction var selectProjectionParser = new SelectProjectionParser <TBase>(this.Configuration); selectProjectionParser.ParseExpression(projectedSelectQuery.ProjectionExpression, rootNode); return(this.InnerGenerateSql(projectedSelectQuery.BaseSelectQuery, new AutoNamingDynamicParameters(), false, rootNode, numberCollectionFetches, new StringBuilder(), true)); }
public SqlWriterResult GenerateCountSql <TBase, TProjection>(ProjectedSelectQuery <TBase, TProjection> projectedSelectQuery) where TBase : class, new() { // get fetch tree structure var rootNode = this.fetchTreeParser.GetFetchTree(projectedSelectQuery.BaseSelectQuery, out _, out var numberCollectionFetches) ?? new FetchNode(); // add in the projection structure var selectProjectionParser = new SelectProjectionParser <TBase>(this.Configuration); selectProjectionParser.ParseExpression(projectedSelectQuery.ProjectionExpression, rootNode); return(this.InnerGenerateCountSql(projectedSelectQuery.BaseSelectQuery, rootNode, numberCollectionFetches)); }
public async Task <Page <TProjection> > QueryPagedAsync <TBase, TProjection>(IDbConnection connection, IDbTransaction transaction, ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { var countQuery = this.countWriter.GenerateCountSql(query); var totalResults = (await connection.QueryAsync <int>(countQuery.Sql, countQuery.Parameters, transaction)).SingleOrDefault(); return(new Page <TProjection> { TotalResults = totalResults, Items = (await this.QueryAsync(connection, transaction, query)).ToArray(), Skipped = query.BaseSelectQuery.SkipN, Taken = query.BaseSelectQuery.TakeN }); }
public async Task <IEnumerable <TProjection> > QueryAsync <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) { var results = await connection.QueryAsync <TBase>(sqlResult.Sql, sqlResult.Parameters, transaction); return(results.Select(query.ProjectionExpression.Compile())); } var projectionExpressionRewriter = new ProjectionExpressionRewriter <TBase, TProjection>(this.configuration, query, sqlResult.FetchTree); var projectionDelegateResult = projectionExpressionRewriter.Rewrite(); return(await connection.QueryAsync <TProjection>(sqlResult.Sql, projectionDelegateResult.Types, projectionDelegateResult.Mapper, sqlResult.Parameters, transaction, splitOn : sqlResult.FetchTree.SplitOn)); }
public Task <Page <TProjection> > QueryPagedAsync <TBase, TProjection>(ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { throw new NotImplementedException("I don't execute queries!"); }
public IEnumerable <TProjection> Query <TBase, TProjection>(ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { throw new NotImplementedException("I don't execute queries!"); }
public async Task <Page <TProjection> > QueryPagedAsync <TBase, TProjection>(IDbConnection connection, IDbTransaction transaction, ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { var pagedBase = await this.QueryPagedAsync(connection, transaction, query.BaseSelectQuery); return(new Page <TProjection> { Items = pagedBase.Items.Select(query.ProjectionExpression.Compile()), Skipped = pagedBase.Skipped, Taken = pagedBase.Taken, TotalResults = pagedBase.TotalResults }); }
public async Task <IEnumerable <TProjection> > QueryAsync <TBase, TProjection>(IDbConnection connection, IDbTransaction transaction, ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { var baseResult = await this.QueryAsync(connection, transaction, query.BaseSelectQuery); return(baseResult.Select(query.ProjectionExpression.Compile())); }
public IEnumerable <TProjection> Query <TBase, TProjection>(IDbConnection connection, IDbTransaction transaction, ProjectedSelectQuery <TBase, TProjection> query) where TBase : class, new() { return(this.Query(connection, transaction, query.BaseSelectQuery).Select(query.ProjectionExpression.Compile())); }