public QueryService(string connectionStringName) { this._connectionFactory = IConnectionFactory.Create(connectionStringName); this._executeQuery = new ExecuteQuery(this._connectionFactory); this._builder = this._connectionFactory.CreateBuilder(); this._joinQuery = this._connectionFactory.CreateJoinBuilder(); }
public static IJoinQuery <TMainEntity, TProperty> ThenInclude <TMainEntity, TSubEntity, TProperty>( this IJoinQuery <TMainEntity, IEnumerable <TSubEntity> > query, Expression <Func <TSubEntity, TProperty> > property) where TMainEntity : class where TSubEntity : class where TProperty : class { var entities = (IIncludableQueryable <TMainEntity, IEnumerable <TSubEntity> >)query.Entities; return(new JoinQuery <TMainEntity, TProperty>(entities.ThenInclude(property))); }
SqlQuery ParseJoinQuery(IJoinQuery joinQuery, out SqlSubQueryResult parentResult) { var result = ParseQuery(joinQuery.Parent, out var tempParentResult); var joinFromSubQuery = ParseQuery(joinQuery.JoinTable); if (joinQuery.JoinTable is IFromQuery) { ParseJoinTableQuery(tempParentResult, joinFromSubQuery, joinQuery, result, out parentResult); return(result); } else { ParseJoinSubQuery(tempParentResult, joinFromSubQuery, joinQuery, result, out parentResult); return(result); } }
/// <summary> /// Retrieves the data from multiple sources as an <see cref="IAsyncEnumerable{T}"/>. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="rowBuilder"> /// The row builder. /// </param> /// <param name="query"> /// The join query expression. Can be <c>null</c>. /// </param> /// <returns> /// A task returning the data set. /// </returns> IAsyncEnumerable <Row> ISupportsJoin.GetRows(IExecutionContext context, IRowBuilder rowBuilder, IJoinQuery query) { throw new NotSupportedException("Join support is not yet implemented."); }
/// <summary> /// Checks if this data source supports the join query. /// </summary> /// <param name="context"> /// The execution context. /// </param> /// <param name="query"> /// The query to check. /// </param> /// <returns><c>true</c> if the <see cref="ISupportsJoin"/> supports the specified <paramref name="query"/>, <c>false</c> otherwise.</returns> bool ISupportsJoin.SupportsJoinQuery(IExecutionContext context, IJoinQuery query) { return(false); }
void ParseJoinTableQuery(SqlSubQueryResult parentResult, SqlQuery joinFromSubQuery, IJoinQuery joinQuery, SqlQuery result, out SqlSubQueryResult joinResult) { // Parameters in both selector & join expressions: actx, a, bctx, b var outerParameters = new Dictionary <string, SqlSubQueryResult>(SubqueryParameters); outerParameters[joinQuery.JoinExpression.Parameters[0].Name] = parentResult; outerParameters[joinQuery.JoinExpression.Parameters[1].Name] = parentResult; outerParameters[joinQuery.JoinExpression.Parameters[2].Name] = joinFromSubQuery.SelectResult; outerParameters[joinQuery.JoinExpression.Parameters[3].Name] = joinFromSubQuery.SelectResult; var joinResultMembers = ParseSelectExpression(joinQuery.ResultExpression, outerParameters); var joinInfo = new SqlJoinTable() { TableAlias = joinFromSubQuery.FromAlias, FromSource = joinFromSubQuery.From, JoinExpression = ParseExpression(joinQuery.JoinExpression.Body, outerParameters), JoinResult = new SqlSubQueryResult() { Members = joinResultMembers, }, JoinType = joinQuery.JoinType, }; result.Joins.Add(joinInfo); joinResult = joinInfo.JoinResult; }
void ParseJoinSubQuery(SqlSubQueryResult parentResult, SqlQuery joinFromSubQuery, IJoinQuery joinQuery, SqlQuery result, out SqlSubQueryResult joinResult) { var joinAlias = AliasProvider.CreateAlias(); // Translate fields from inside the subquery to fields rooted in the subquery usable from the outside var tempFromSubQuery = new SqlSubQueryResult() { Members = joinFromSubQuery.SelectResult.Members.Select(m => new SqlJoinFieldMember() { JoinAlias = joinAlias, SourceField = m, MemberName = m.MemberName, MemberInfo = m.MemberInfo, SqlName = m.MemberName, FieldType = m.FieldType, }).ToList <SqlMember>(), }; // Parameters in both selector & join expressions: actx, a, bctx, b var outerParameters = new Dictionary <string, SqlSubQueryResult>(SubqueryParameters); outerParameters[joinQuery.JoinExpression.Parameters[0].Name] = parentResult; outerParameters[joinQuery.JoinExpression.Parameters[1].Name] = parentResult; outerParameters[joinQuery.JoinExpression.Parameters[2].Name] = tempFromSubQuery; outerParameters[joinQuery.JoinExpression.Parameters[3].Name] = tempFromSubQuery; var joinResultMembers = ParseSelectExpression(joinQuery.ResultExpression, outerParameters); var joinInfo = new SqlJoinSubQuery() { JoinAlias = joinAlias, JoinResult = new SqlSubQueryResult() { Members = joinResultMembers, }, JoinFrom = joinFromSubQuery, JoinExpression = ParseExpression(joinQuery.JoinExpression.Body, outerParameters), JoinType = joinQuery.JoinType, }; result.Joins.Add(joinInfo); joinResult = joinInfo.JoinResult; }