/// <summary> /// 初始化Sql连接语句抽象类 /// </summary> /// <param name="baseCommand">源选择语句</param> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableField">另个表格主键</param> protected AbstractSqlJoin(SelectCommand baseCommand, SqlJoinType joinType, String currentTableName, String currentTableField, String anotherTableField) { this._joinType = joinType; this._currentTableName = currentTableName; this._currentTableKeyField = currentTableField; this._anotherTableKeyField = anotherTableField; }
/// <summary> /// Initializes a new instance of the <see cref="SqlJoinExpression"/> class. /// </summary> /// <param name="left">The left expression.</param> /// <param name="right">The right expression.</param> /// <param name="condition">The "on" condition.</param> /// <param name="joinType">Type of the join.</param> public SqlJoinExpression(SqlExpression left, SqlExpression right, SqlExpression condition, SqlJoinType joinType) { Left = left; Right = right; Condition = condition; JoinType = joinType; }
public static IEnumerable<TResult> SqlJoinInternal<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, [JetBrains.Annotations.NotNull] IEnumerable<TSecond> second, Func<TFirst, TSecond, bool> predicate, Func<TFirst, TSecond, TResult> resultSelector, SqlJoinType joinType) { if (first == null) throw new ArgumentNullException("first"); if (second == null) throw new ArgumentNullException("second"); switch (joinType) { case SqlJoinType.Inner: return first.SelectMany(f => second.Where(s => predicate(f, s)).Select(s => resultSelector(f, s))); case SqlJoinType.Left: return first.SelectMany(f => second.Where(s => predicate(f, s)).DefaultIfEmpty().Select(s => resultSelector(f, s))); case SqlJoinType.Right: return second.SelectMany(s => first.Where(f => predicate(f, s)).DefaultIfEmpty().Select(f => resultSelector(f, s))); case SqlJoinType.Full: var firstItems = first.ToList(); var secondItems = second.ToList(); var firstResult = firstItems.SelectMany(f => secondItems.Where(s => predicate(f, s)).DefaultIfEmpty().Select(s => new {First = f, Second = s})); var secondResult = secondItems.Where(s => !firstItems.Any(f => predicate(f, s))) .Select(s => new {First = default(TFirst), Second = s}); var res = firstResult.Concat(secondResult).Select(r => resultSelector(r.First, r.Second)); return res; default: throw new ArgumentOutOfRangeException("joinType", joinType, null); } }
internal SqlJoin(SqlJoinType type, SqlTable table, SqlExpression predicate = null) { if (table == null) throw new ArgumentNullException(nameof(table)); Type = type; Table = table; On = predicate == null ? null : new SqlOn(predicate); }
private void AddGenericJoin(string table, string column, string target, string targetColumn, string key, object value, SqlDbType type, SqlJoinType joinType) { if (this.innerJoins.Keys.Contains(table)) { SqlJoinItem item = this.innerJoins[table]; if (!item.HasCompare(column)) { item.AddCompare(column, target, targetColumn); } if (!item.HasColumn(key) && !key.Equals(string.Empty)) { Query.SqlWhereItem ijItem = new Query.SqlWhereItem(key, value, type); item.Items.Add(key, ijItem); } } else { SqlJoinItem item = new SqlJoinItem(); item.Type = joinType; item.AddCompare(column, target, targetColumn); if (!key.Equals(string.Empty)) { Query.SqlWhereItem ijItem = new Query.SqlWhereItem(key, value, type); item.Items.Add(key, ijItem); } this.innerJoins.Add(table, item); } }
public SqlJoin(ISqlTable leftTable, SqlJoinType joinType, ISqlTable rightTable, IEnumerable <ISqlFilter> conditions) { this.LeftTable = leftTable; this.JoinType = joinType; this.RightTable = rightTable; this.Conditions.AddRange(conditions); }
public void BuildJoinTable(SqlJoinType type, Type tableType, string aliasName) { string tableName = this.GetTableName(tableType, aliasName); string joinString = string.Format("{0} JOIN {1} ON", type.ToString(), tableName); _joins.Add(joinString); }
internal SqlJoin(SqlJoinType type, SqlSource left, SqlSource right, SqlExpression cond, Expression sourceExpression) : base(SqlNodeType.Join, sourceExpression) { this.JoinType = type; this.Left = left; this.Right = right; this.Condition = cond; }
// Constructor internal SqlJoinExpression(SqlJoinType joinType, SqlTable left, SqlTable right, SqlExpression expression) : base(SqlNodeType.Join) { JoinType = joinType; Left = left; Right = right; Expression = expression; }
public SqlJoin(SqlTable left, SqlTable right, SqlJoinType type, SqlColumn col1, SqlColumn col2) { Left = left; Right = right; Type = type; Column1 = col1; Column2 = col2; }
public SqlJoinTableSource(SqlFromClause sqlFromClause, SqlTableAlias leftTable, SqlTableAlias rightTable, SqlJoinType joinType) : base(sqlFromClause) { this.Parent = sqlFromClause; this.leftSqlTableAlias = leftTable; this.rightTableAlias = rightTable; this.sqlJoinType = joinType; }
protected SqlJoinExpression UpdateJoin(SqlJoinExpression join, SqlJoinType joinType, Expression left, Expression right, Expression condition) { if (joinType != join.JoinType || left != join.Left || right != join.Right || condition != join.JoinCondition) { return(new SqlJoinExpression(join.Type, joinType, left, right, condition)); } return(join); }
protected SqlJoinExpression UpdateJoin(SqlJoinExpression join, SqlJoinType joinType, Expression left, Expression right, Expression condition) { if (joinType != join.JoinType || left != join.Left || right != join.Right || condition != join.JoinCondition) { return new SqlJoinExpression(join.Type, joinType, left, right, condition); } return join; }
internal SqlJoin(SqlJoinType type, SqlTable table, SqlExpression predicate = null) { if (table == null) { throw new ArgumentNullException(nameof(table)); } Type = type; Table = table; On = predicate == null ? null : new SqlOn(predicate); }
protected bool RequiresOnCondition(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.Cross: case SqlJoinType.RightOuter: return false; } return true; }
protected bool RequiresOnCondition(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.Cross: case SqlJoinType.RightOuter: return(false); } return(true); }
/// <summary> /// 初始化Sql连接语句类 /// </summary> /// <param name="cmd">选择语句</param> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableName">另个表格名称</param> /// <param name="createSelectAction">创建查询方法</param> /// <param name="anotherTableIdentity">标识</param> /// <param name="anotherTableField">另个表格主键</param> internal SqlJoinTableCommand(SelectCommand cmd, SqlJoinType joinType, String currentTableName, String currentTableField, String anotherTableName, String anotherTableField, String anotherTableIdentity, Action<SelectCommand> createSelectAction) : base(cmd, joinType, currentTableName, currentTableField, anotherTableField) { this._anotherTableIdentity = anotherTableIdentity; SelectCommand anotherTableCommand = cmd.Database.InternalCreateSelectCommand((cmd.RootSource == null ? cmd : cmd.RootSource), anotherTableName); createSelectAction(anotherTableCommand); this._anotherTableCommand = anotherTableCommand; }
/// <summary> /// Default constructor. /// </summary> public StatementSqlBuilderJoinInstruction( GenericStatementSqlBuilder sqlBuilder, SqlJoinType joinType, FormattableString whereClause, FormattableString orderClause) { this.SqlBuilder = sqlBuilder; this.JoinType = joinType; this.WhereClause = whereClause; this.OrderClause = orderClause; }
/// <summary> /// Default constructor. /// </summary> public StatementSqlBuilderJoinInstruction( GenericStatementSqlBuilder sqlBuilder, SqlJoinType joinType, FormattableString whereClause, FormattableString orderClause) { SqlBuilder = sqlBuilder; JoinType = joinType; WhereClause = whereClause; OrderClause = orderClause; }
/// <summary> /// 初始化Sql连接语句类 /// </summary> /// <param name="cmd">选择语句</param> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableName">另个表格名称</param> /// <param name="createSelectAction">创建查询方法</param> /// <param name="anotherTableIdentity">标识</param> /// <param name="anotherTableField">另个表格主键</param> internal SqlJoinTableCommand(SelectCommand cmd, SqlJoinType joinType, String currentTableName, String currentTableField, String anotherTableName, String anotherTableField, String anotherTableIdentity, Action <SelectCommand> createSelectAction) : base(cmd, joinType, currentTableName, currentTableField, anotherTableField) { this._anotherTableIdentity = anotherTableIdentity; SelectCommand anotherTableCommand = cmd.Database.InternalCreateSelectCommand((cmd.RootSource == null ? cmd : cmd.RootSource), anotherTableName); createSelectAction(anotherTableCommand); this._anotherTableCommand = anotherTableCommand; }
private ISqlJoinClause JoinInternal(SqlJoinType type, SqlTable table, SqlExpression predicate = null) { if (table == null) { throw new ArgumentNullException(nameof(table)); } var join = new SqlJoin(type, table); Parent.From.AddJoin(join); return(new JoinClause(this, join)); }
internal SqlJoin MakeJoin(SqlJoinType joinType, SqlSource location, SqlAlias alias, SqlExpression condition, Expression source) { if (joinType == SqlJoinType.LeftOuter) { var sqlSelect = alias.Node as SqlSelect; if (sqlSelect != null && sqlSelect.Selection != null && sqlSelect.Selection.NodeType != SqlNodeType.OptionalValue) { sqlSelect.Selection = new SqlOptionalValue(new SqlColumn("test", Unary(SqlNodeType.OuterJoinedValue, Value(typeof(int?), TypeProvider.From(typeof(int)), 1, false, source))), sqlSelect.Selection); } } return(new SqlJoin(joinType, location, alias, condition, source)); }
public void JoinMergeHintTest( [IncludeDataSources(true, TestProvName.AllSqlServer)] string context, [Values(SqlJoinType.Inner, SqlJoinType.Left, SqlJoinType.Full)] SqlJoinType joinType) { using var db = GetDataContext(context); var q = db.Child.Join(db.Parent.AsSqlServer().JoinMergeHint(), joinType, (c, p) => c.ParentID == p.ParentID, (c, p) => p); _ = q.ToList(); Assert.That(LastQuery, Contains.Substring($"{joinType.ToString().ToUpper()} MERGE JOIN")); }
public void JoinHintMethodTest( [IncludeDataSources(true, TestProvName.AllSqlServer)] string context, [Values(SqlServerHints.Join.Loop, SqlServerHints.Join.Hash, SqlServerHints.Join.Merge)] string hint, [Values(SqlJoinType.Left, SqlJoinType.Full)] SqlJoinType joinType) { using var db = GetDataContext(context); var q = db.Child.Join(db.Parent.JoinHint(hint), joinType, (c, p) => c.ParentID == p.ParentID, (c, p) => p); _ = q.ToList(); Assert.That(LastQuery, Contains.Substring($"{joinType.ToString().ToUpper()} {hint} JOIN")); }
public static IEnumerable <TResult> SqlJoinInternal <TOuter, TInner, TResult>( this IEnumerable <TOuter> outer, IEnumerable <TInner> inner, SqlJoinType joinType, Func <TOuter, TInner, bool> predicate, Func <TOuter, TInner, TResult> resultSelector) { if (outer == null) { throw new ArgumentNullException(nameof(outer)); } if (inner == null) { throw new ArgumentNullException(nameof(inner)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (resultSelector == null) { throw new ArgumentNullException(nameof(resultSelector)); } switch (joinType) { case SqlJoinType.Inner: return(outer.SelectMany(f => inner.Where(s => predicate(f, s)).Select(s => resultSelector(f, s)))); case SqlJoinType.Left: return(outer.SelectMany(f => inner.Where(s => predicate(f, s)).DefaultIfEmpty().Select(s => resultSelector(f, s)))); case SqlJoinType.Right: return(inner.SelectMany(s => outer.Where(f => predicate(f, s)).DefaultIfEmpty().Select(f => resultSelector(f, s)))); case SqlJoinType.Full: var firstItems = outer.ToList(); var secondItems = inner.ToList(); var firstResult = firstItems.SelectMany(f => secondItems.Where(s => predicate(f, s)).DefaultIfEmpty().Select(s => new { First = f, Second = s })); var secondResult = secondItems.Where(s => !firstItems.Any(f => predicate(f, s))) .Select(s => new { First = default(TOuter), Second = s }); var res = firstResult.Concat(secondResult).Select(r => resultSelector(r.First, r.Second)); return(res); default: throw new ArgumentOutOfRangeException(nameof(joinType), joinType, null); } }
protected override void Write(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.CrossApply: this.Write(" CROSS JOIN LATERAL "); break; case SqlJoinType.OuterApply: this.Write(" OUTER JOIN LATERAL "); break; default: base.Write(joinType); break; } }
public static IEnumerable<TResult> SqlJoinInternal<TFirst, TSecond, TKey, TResult>(this IEnumerable<TFirst> first, [JetBrains.Annotations.NotNull] IEnumerable<TSecond> second, Func<TFirst, TKey> firstKeySelector, Func<TSecond, TKey> secondKeySelector, Func<TFirst, TSecond, TResult> resultSelector, SqlJoinType joinType) { if (first == null) throw new ArgumentNullException("first"); if (second == null) throw new ArgumentNullException("second"); switch (joinType) { case SqlJoinType.Inner: return first.Join(second, firstKeySelector, secondKeySelector, resultSelector); case SqlJoinType.Left: return first .GroupJoin(second, firstKeySelector, secondKeySelector, (o, gr) => new {o, gr}) .SelectMany(t => t.gr.DefaultIfEmpty(), (t1, t2) => resultSelector(t1.o, t2)); case SqlJoinType.Right: return second .GroupJoin(first, secondKeySelector, firstKeySelector, (o, gr) => new { o, gr }) .SelectMany(t => t.gr.DefaultIfEmpty(), (t1, t2) => resultSelector(t2, t1.o)); case SqlJoinType.Full: var keys1 = first.ToLookup(firstKeySelector); var keys2 = second.ToLookup(secondKeySelector); var res = new List<TResult>(); foreach (var pair1 in keys1) { if (keys2.Contains(pair1.Key)) { res.AddRange(pair1.Join(keys2[pair1.Key], firstKeySelector, secondKeySelector, resultSelector)); continue; } res.AddRange(pair1.Select(r => resultSelector(r, default(TSecond)))); } foreach (var pair2 in keys2) { if (keys1.Contains(pair2.Key)) { continue; } res.AddRange(pair2.Select(r => resultSelector(default(TFirst), r))); } return res; default: throw new ArgumentOutOfRangeException("joinType", joinType, null); } }
public SqlJoinExpression(Type type, SqlJoinType joinType, Expression left, Expression right, Expression joinCondition) : base(type) { if (joinType != SqlJoinType.OuterApply && joinType != SqlJoinType.CrossApply && joinType != SqlJoinType.Cross) { if (joinCondition == null) { throw new ArgumentNullException(nameof(joinCondition)); } } this.JoinType = joinType; this.Left = left; this.Right = right; this.JoinCondition = joinCondition; }
public SqlJoinExpression(Type type, SqlJoinType joinType, Expression left, Expression right, Expression joinCondition) : base(type) { if (joinType != SqlJoinType.CrossApply && joinType != SqlJoinType.CrossJoin) { if (joinCondition == null) { throw new ArgumentNullException("joinCondition"); } } this.JoinType = joinType; this.Left = left; this.Right = right; this.JoinCondition = joinCondition; }
/// <summary> /// Visits the specified join type. /// </summary> /// <param name="joinType">Type of the join.</param> /// <returns>Returns processed value from expression.</returns> /// <exception cref="System.ArgumentOutOfRangeException">joinType - null</exception> protected string Visit(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.Inner: return("INNER"); case SqlJoinType.LeftOuter: return("LEFT OUTER"); case SqlJoinType.RightOuter: return("RIGHT OUTER"); case SqlJoinType.Full: return("FULL"); default: throw new ArgumentOutOfRangeException(nameof(joinType), joinType, null); } }
public virtual void RenderJoin(ISqlTable leftTable, SqlJoinType joinType, ISqlTable rightTable, IEnumerable <ISqlFilter> conditions, SqlBuildArguments args) { this.WriteSpace(); this.Write(joinType.ToString().ToUpper()); this.WriteSpace(); this.Write("JOIN"); this.WriteSpace(); //TODO: This is causing joined tables to render their conditions here, which is not right. rightTable.Render(this, args); if (joinType != SqlJoinType.Cross) { this.WriteSpace(); this.Write(SqlConstants.ON); this.WriteSpace(); this.RenderAll <ISqlFilter>(conditions, args, string.Concat(SqlConstants.SPACE, ConvertSqlLogicToString(SqlLogic.And), SqlConstants.SPACE)); } this.WriteNewLine(); }
public void SqlNullWhereSubqueryJoin( [AllJoinsSource] string context, [Values(SqlJoinType.Inner, SqlJoinType.Left, SqlJoinType.Right, SqlJoinType.Full)] SqlJoinType joinType) { using (var db = GetDataContext(context)) { var expected = Parent.Take(10).SqlJoinInternal(Parent.Take(10), (p1, p) => p1.ParentID == p.ParentID && p1.Value1 == p.Value1, (p1, p2) => p2, joinType); var actual = from p1 in db.Parent.Take(10) from p2 in db.Parent.Take(10).Join(joinType, p => p1.ParentID == p.ParentID && p1.Value1 == p.Value1) select p2; AreEqual(expected.ToList().OrderBy(r => r.ParentID).ThenBy(r => r.Value1), actual.ToList().OrderBy(r => r.ParentID).ThenBy(r => r.Value1)); } }
internal SqlJoin MakeJoin(SqlJoinType joinType, SqlSource location, SqlAlias alias, SqlExpression condition, Expression source) { // if the new item is on the right side of some outer join then fixup the projection to reflect that it can possibly be null if (joinType == SqlJoinType.LeftOuter) { SqlSelect sel = alias.Node as SqlSelect; if (sel != null && sel.Selection != null && sel.Selection.NodeType != SqlNodeType.OptionalValue) { // replace selection w/ optional + outer-joined-value sel.Selection = new SqlOptionalValue( new SqlColumn( "test", this.Unary(SqlNodeType.OuterJoinedValue, this.Value(typeof(int?), this.typeProvider.From(typeof(int)), 1, false, source)) ), sel.Selection ); } } return(new SqlJoin(joinType, location, alias, condition, source)); }
public void SqlJoinSubQuery( [AllJoinsSource] string context, [Values(SqlJoinType.Inner, SqlJoinType.Left, SqlJoinType.Right, SqlJoinType.Full)] SqlJoinType joinType) { using (var db = GetDataContext(context)) { var expected = from p in Parent.Where(p => p.ParentID > 0).Take(10) .SqlJoinInternal(Child, (p, c) => p.ParentID == c.ParentID, (p, c) => new { p, c }, joinType) select new { ParentID = p.p == null ? (int?)null : p.p.ParentID, ChildID = p.c == null ? (int?)null : p.c.ChildID }; var actual = from p in db.Parent.Where(p => p.ParentID > 0).Take(10) from c in db.Child.Join(joinType, r => p.ParentID == r.ParentID) select new { ParentID = (int?)p.ParentID, ChildID = (int?)c.ChildID }; AreEqual(expected.ToList().OrderBy(r => r.ParentID).ThenBy(r => r.ChildID), actual.ToList().OrderBy(r => r.ParentID).ThenBy(r => r.ChildID)); } }
/// <summary> /// 连接语句并返回当前语句 /// </summary> /// <typeparam name="T">实体类类型</typeparam> /// <typeparam name="TAnother">另个表格的实体类类型</typeparam> /// <param name="cmd">查询语句</param> /// <param name="joinType">连接模式</param> /// <param name="currentExpr">当前实体类主键属性</param> /// <param name="anotherAction">设置选择语句的方法</param> /// <param name="anotherExpr">另个实体类主键属性</param> /// <exception cref="ExpressionInvalidException">表达式不正确</exception> /// <exception cref="NullAttributeException">没有设置特性</exception> /// <returns>当前语句</returns> public static SelectCommand Join <T, TAnother>(this SelectCommand cmd, SqlJoinType joinType, Expression <Func <T, Object> > currentExpr, Action <SelectCommand> anotherAction, Expression <Func <TAnother, Object> > anotherExpr) { MemberExpression currentLeft = ExpressionHelper.GetMemberExpression(currentExpr.Body); MemberExpression anotherLeft = ExpressionHelper.GetMemberExpression(anotherExpr.Body); if (currentLeft == null || anotherLeft == null) { throw new ExpressionInvalidException(); } DatabaseColumnAttribute currentAttr = ExpressionHelper.GetColumnAttribute(cmd, currentLeft); DatabaseColumnAttribute anotherAttr = ExpressionHelper.GetColumnAttribute(cmd, anotherLeft); if (currentAttr == null || anotherAttr == null) { throw new NullAttributeException(); } String anotherTableName = EntityHelper.InternalGetTableName(typeof(TAnother)); return(cmd.Join(joinType, currentAttr.ColumnName, anotherTableName, anotherAttr.ColumnName, anotherAction)); }
public static string AsString(this SqlJoinType value) { switch (value) { case SqlJoinType.CrossJoin: return("Cross Join"); case SqlJoinType.FullOuterJoin: return("Full Outer Join"); case SqlJoinType.InnerJoin: return("Inner Join"); case SqlJoinType.LeftOuterJoin: return("Left Outer Join"); case SqlJoinType.RightOuterJoin: return("Right Outer Join"); default: throw new ArgumentOutOfRangeException("value"); } }
public void ResolveJoin <T, TResult>(Expression <Func <T, TResult, bool> > expression, string aliasName, SqlJoinType type) { var body = expression.Body; if (builder.ContainsBinaryNodeType(body.NodeType)) { Type tableType = typeof(TResult); string tableName = tableType.Name; builder.TableType = tableType; builder.AddTableName(tableName, aliasName); builder.BuildJoinTable(type, tableName, aliasName); var node = ResolveQuery((dynamic)body); builder.BuildJoin(node); } else { throw new ArgumentException("不能解析Join条件表达式", "expression"); } }
internal bool RequiresOnCondition(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.CrossApply: case SqlJoinType.Cross: case SqlJoinType.OuterApply: return false; case SqlJoinType.Inner: case SqlJoinType.LeftOuter: return true; default: throw Error.InvalidFormatNode(joinType); } }
/// <summary> /// 初始化Sql连接语句类 /// </summary> /// <param name="cmd">选择语句</param> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableName">另个表格名称</param> /// <param name="anotherTableField">另个表格主键</param> internal SqlJoinTableName(SelectCommand cmd, SqlJoinType joinType, String currentTableName, String currentTableField, String anotherTableName, String anotherTableField) : base(cmd, joinType, currentTableName, currentTableField, anotherTableField) { this._anotherTableName = anotherTableName; }
protected virtual void Write(SqlJoinType joinType) { switch (joinType) { case SqlJoinType.Cross: this.Write(" CROSS JOIN "); break; case SqlJoinType.Inner: this.Write(" INNER JOIN "); break; case SqlJoinType.Left: this.Write(" LEFT JOIN "); break; case SqlJoinType.Right: this.Write(" RIGHT JOIN "); break; case SqlJoinType.Outer: this.Write(" FULL OUTER JOIN "); break; case SqlJoinType.CrossApply: this.Write(" CROSS APPLY "); break; case SqlJoinType.OuterApply: this.Write(" OUTER APPLY "); break; default: throw new ArgumentOutOfRangeException(nameof(joinType), joinType, $"JoinType {joinType} not supported"); } }
/// <summary> /// 初始化Sql连接语句类 /// </summary> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableName">另个表格名称</param> /// <param name="anotherTableField">另个表格主键</param> internal SqlJoinTableName(SqlJoinType joinType, String currentTableName, String currentTableField, String anotherTableName, String anotherTableField) : base(joinType, currentTableName, currentTableField, anotherTableField) { this._anotherTableName = anotherTableName; }
/// <summary> /// 连接语句并返回当前语句 /// </summary> /// <param name="joinType">连接模式</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableCommand">另个表格命令</param> /// <param name="anotherTableField">另个表格主键</param> /// <returns>当前语句</returns> public SelectCommand Join(SqlJoinType joinType, String currentTableField, SelectCommand anotherTableCommand, String anotherTableField) { this._joins.Add(new SqlJoinTableCommand(joinType, this._tableName, currentTableField, anotherTableCommand, this.SqlJoins.Count, anotherTableField)); return this; }
/// <summary> /// 获取连接类型名称 /// </summary> /// <param name="type">连接类型</param> /// <returns>连接类型名称</returns> internal static String InternalGetTypeName(SqlJoinType type) { Byte index = (Byte)type; return TypeNames[index]; }
internal SqlJoin MakeJoin(SqlJoinType joinType, SqlSource location, SqlAlias alias, SqlExpression condition, Expression source) { // if the new item is on the right side of some outer join then fixup the projection to reflect that it can possibly be null if (joinType == SqlJoinType.LeftOuter) { SqlSelect sel = alias.Node as SqlSelect; if (sel != null && sel.Selection != null && sel.Selection.NodeType != SqlNodeType.OptionalValue) { // replace selection w/ optional + outer-joined-value sel.Selection = new SqlOptionalValue( new SqlColumn( "test", this.Unary(SqlNodeType.OuterJoinedValue, this.Value(typeof(int?), this.typeProvider.From(typeof(int)), 1, false, source)) ), sel.Selection ); } } return new SqlJoin(joinType, location, alias, condition, source); }
public SqlJoinTableSource AddSqlJoinTableSource(SqlTableAlias leftTable, SqlTableAlias rightTable, SqlJoinType joinType) { return new SqlJoinTableSource(this, leftTable, rightTable, joinType) ; }
/// <summary> /// 初始化Sql连接语句类 /// </summary> /// <param name="joinType">连接模式</param> /// <param name="currentTableName">当前表格名称</param> /// <param name="currentTableField">当前表格主键</param> /// <param name="anotherTableCommand">另个表格命令</param> /// <param name="anotherTableIndentity">标识</param> /// <param name="anotherTableField">另个表格主键</param> internal SqlJoinTableCommand(SqlJoinType joinType, String currentTableName, String currentTableField, SelectCommand anotherTableCommand, Int32 anotherTableIndentity, String anotherTableField) : base(joinType, currentTableName, currentTableField, anotherTableField) { this._anotherTableIndentity = anotherTableIndentity; this._anotherTableCommand = anotherTableCommand; }