public void LeftJoin <TEntity1, TEntity2>() { var entityRef = AddInvolveEntity <TEntity1>(); var entityJoin = AddInvolveEntity <TEntity2>(); JoinList.Add(new LeftJoin(entityRef, entityJoin)); }
// ReSharper disable once ParameterTypeCanBeEnumerable.Local private void Expand(JoinList joins) { var joinTypes = new Dictionary <JoinType, string>() { { JoinType.Inner, "inner" }, { JoinType.LeftOuter, "left outer" }, { JoinType.RightOuter, "right outer" }, { JoinType.FullOuter, "full outer" }, { JoinType.Cross, "cross" }, }; var head = true; foreach (var join in joins) { if (head) { head = false; } else { builder.AppendLine(); } if (join.JoinType != JoinType.Inner) { builder.Append(joinTypes[join.JoinType]).Append(" "); } builder.Append("join "); ExpandExpression(join.Source); builder.Append(" on "); ExpandExpression(join.Expression); } }
///<summary> /// Creates a source ///</summary> ///<param name="name"></param> ///<param name="entityName"></param> public Source(string name, string entityName) { _joins = new JoinList(this); _inheritanceJoins = new JoinList(this); _name = name; _entityName = entityName; }
public void LeftJoin(ICondition condition) { var entityRef = AddInvolveEntity(condition.Entity1.EntityType); var entityJoin = AddInvolveEntity(condition.Entity2.EntityType); JoinList.Add(new LeftJoin(entityRef, entityJoin, condition)); }
public Query Join(JoinType joinType, object rightTableSql, string rightTableAlias, params JoinColumnPair[] pairs) { if (_ListJoin == null) _ListJoin = new JoinList(); Join join = new Join(joinType, rightTableSql, rightTableAlias, pairs); _ListJoin.Add(join); return this; }
public Query Join(JoinType joinType, TableSchema leftTableSchema, string leftColumn, string leftTableAlias, object rightTableSql, string rightColumn, string rightTableAlias) { if (_ListJoin == null) _ListJoin = new JoinList(); Join join = new Join(joinType, leftTableSchema, leftColumn, leftTableAlias, rightTableSql, rightColumn, rightTableAlias); _ListJoin.Add(join); return this; }
public Query Join(JoinType joinType, TableSchema rightTableSchema, string rightTableAlias, params JoinColumnPair[] pairs) { if (_ListJoin == null) _ListJoin = new JoinList(); Join join = new Join(joinType, rightTableSchema, rightTableAlias, pairs); _ListJoin.Add(join); TableAliasMap[join.RightTableAlias] = join.RightTableSchema; return this; }
/// <summary> /// Create a new Filter, "rooted" at the associated entity, assigning the given alias and using the specified join type. /// </summary> /// <param name="associationPath">Property path</param> /// <param name="alias">The alias to assign to the joined association (for later reference).</param> /// <param name="joinType">The type of join to use</param> /// <returns>The created "sub criteria"</returns> public IFilter CreateCriteria(string associationPath, string alias, JoinType joinType) { SubFilter subFilter = new SubFilter(this, associationPath, alias, joinType); int hashCode = subFilter.GetHashCode(); if (JoinList.ContainsKey(hashCode)) { return((IFilter)JoinList[hashCode]); } return(subFilter); }
public Select(IFormatter parameters, string tableAlias = "") { Query = SqlQuery.Select; Formatter = parameters; TableAlias = tableAlias; Columns = new ColumnsListAggregation(Formatter); Join = new JoinList(Formatter); Where = new WhereList(Formatter); OrderBy = new OrderByList(Formatter); GroupBy = new GroupByList(Formatter, Columns); }
public void JoinSimpleTwoTables() { JoinList list = new JoinList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter); Join j1 = new Join("users"); j1.Append("id_user", "id").Append("id_admin", "id"); list.Append(j1); Join j2 = new Join("profiles", "p", JoinType.LEFT); j2.Append("id_profile", "id"); list.Append(j2); string result = list.GetSql("t"); string sql = "INNER JOIN [users] ON [t].[id_user]=[users].[id] AND [t].[id_admin]=[users].[id] LEFT JOIN [profiles] as [p] ON [t].[id_profile]=[p].[id]"; Assert.Equal(result, sql); }
/// <summary> /// Merges a given list of joins into this one /// </summary> /// <param name="joinListToMerge">The list of joins to add to this one</param> public void MergeWith(JoinList joinListToMerge) { Source fromSourceToMerge = joinListToMerge.FromSource; if (!_fromSource.Equals(fromSourceToMerge)) { throw new HabaneroDeveloperException( "A source's joins cannot merge with another source's joins " + "if they do not have the same base source.", "Please check your Source structures. Base Source:" + this + ", Source to merge:" + fromSourceToMerge); } if (joinListToMerge.Count == 0) { return; } Join inheritanceJoinToMerge = joinListToMerge[0]; Source toSourceToMerge = inheritanceJoinToMerge.ToSource; Join inheritanceJoin; Source toSource = null; if (this.Count > 0) { inheritanceJoin = this[0]; toSource = inheritanceJoin.ToSource; } if (!Equals(toSourceToMerge, toSource)) { toSource = toSourceToMerge; Join newJoin = this.AddNewJoinTo(toSourceToMerge, inheritanceJoinToMerge.JoinType); if (newJoin != null) { foreach (Join.JoinField joinField in inheritanceJoinToMerge.JoinFields) { newJoin.JoinFields.Add(joinField); } } } if (toSource != null) { toSource.MergeWith(toSourceToMerge); } }
public void JoinSimpleTwoTables() { JoinList list = new JoinList(global::SqlBuilder.Format.MsSQL); Join j1 = new Join(global::SqlBuilder.Format.MsSQL, "users"); j1.Append("id_user", "id").Append("id_admin", "id"); list.Append(j1); Join j2 = new Join(global::SqlBuilder.Format.MsSQL, "profiles", "p", Enums.JoinType.LEFT); j2.Append("id_profile", "id"); list.Append(j2); string result = list.GetSql("t"); string sql = "INNER JOIN [users] ON [t].[id_user]=[users].[id] AND [t].[id_admin]=[users].[id] LEFT JOIN [profiles] as [p] ON [t].[id_profile]=[p].[id]"; Assert.AreEqual(result, sql); }
protected string JoinStatement(List <IDataParameter> @params) { return(JoinList.Aggregate(string.Empty, (current, join) => current + " " + join.ToStatement(@params))); }