Exemplo n.º 1
0
 public JoinClause(ObjectReference table, JoinType joinType, SimpleExpression joinExpression)
 {
     if (table == null) throw new ArgumentNullException("table");
     _table = table;
     _joinType = joinType;
     _joinExpression = joinExpression;
 }
Exemplo n.º 2
0
 public Table(Type memberType, JoinType joinType)
 {
     EntityType = memberType;
     Name = memberType.GetTableName();
     JoinType = joinType;
     Columns = MapRepository.Instance.GetColumns(memberType);
 }
        /// <summary>
        /// Jet engine does not support full joins.
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="alias"></param>
        /// <param name="fkColumns"></param>
        /// <param name="pkColumns"></param>
        /// <param name="joinType"></param>
        public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType)
        {
            if (joinType == JoinType.FullJoin)
                throw new NotSupportedException("The FULL JOIN is not supported by Jet database engine.");

            base.AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
        }
 public PrettyPolyMeshLayer()
     : base()
 {
     minTileSize = 100;
     outerJoinType = JoinType.Rounded;
     innerJoinType = JoinType.Rounded;
 }
		public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType)
		{
			switch (joinType)
			{
				case JoinType.InnerJoin:
					AddCrossJoin(tableName, alias);
					break;
				case JoinType.LeftOuterJoin:
					afterFrom.Add(StringHelper.CommaSpace).Add("outer ").Add(tableName).Add(" ").Add(alias);
					break;
				case JoinType.RightOuterJoin:
					int i = GetPrevTableInsertPoint(afterFrom.ToSqlString());
					afterFrom.Insert(i, "outer ");
					break;
				case JoinType.FullJoin:
					throw new NotSupportedException("join type not supported by Informix");
				default:
					throw new AssertionFailure("undefined join type");
			}

			for (int j = 0; j < fkColumns.Length; j++)
			{
				HasThetaJoins = true;
				afterWhere.Add(" and " + fkColumns[j]);
				afterWhere.Add("=" + alias + StringHelper.Dot + pkColumns[j]);
			}
		}
Exemplo n.º 6
0
 public JoinedTable(JoinType Type, IQueryTable OuterTable, string InnerKey, string OuterKey)
 {
     this.OuterTable = OuterTable;
     this.InnerKey = InnerKey;
     this.OuterKey = OuterKey;
     this.Type = Type;
 }
		public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
		                             SqlString on)
		{
			string joinString;
			switch (joinType)
			{
				case JoinType.InnerJoin:
					joinString = " inner join ";
					break;
				case JoinType.LeftOuterJoin:
					joinString = " left outer join ";
					break;
				case JoinType.RightOuterJoin:
					joinString = " right outer join ";
					break;
				case JoinType.FullJoin:
					joinString = " full outer join ";
					break;
				default:
					throw new AssertionFailure("undefined join type");
			}

			_fromFragment.Add(joinString + tableName + ' ' + alias + " on ");

			for (int j = 0; j < fkColumns.Length; j++)
			{
				_fromFragment.Add(fkColumns[j] + "=" + alias + StringHelper.Dot + pkColumns[j]);
				if (j < fkColumns.Length - 1)
				{
					_fromFragment.Add(" and ");
				}
			}

			AddCondition(_fromFragment, on);
		}
		public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
		                             SqlString on)
		{
			//arbitrary on clause ignored!!
			AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
			AddCondition(on);
		}
Exemplo n.º 9
0
 public void JoinAt(int betweenIndex, JoinType joinType, SqlExpression onExpression)
 {
     var planLeft = tablePlans[betweenIndex];
     var planRight = tablePlans[betweenIndex + 1];
     planLeft.RightJoin(planRight, joinType, onExpression);
     planRight.LeftJoin(planLeft, joinType, onExpression);
 }
 /// <summary>
 /// Construct a CreateAliasEvent
 /// Construct a CreateAliasEvent
 /// </summary>
 /// <param name="methodSig">The signature of the createAlias method we're going to invoke when the event fires</param>
 /// <param name="associationPath">the association path of the alias we're creating</param>
 /// <param name="alias"> the name of the alias we're creating</param>
 /// <param name="joinType">the join type of the alias we're creating. Can be null</param>
 private CreateAliasEvent(MethodSig methodSig, string associationPath, string alias, JoinType joinType)
 {
     this.methodSig = methodSig;
     this.associationPath = associationPath;
     this.alias = alias;
     this.joinType = joinType;
 }
Exemplo n.º 11
0
        public Join(string fromTableName, string fromColumnName, string toTableName, string toColumnName, JoinType joinType)
        {
            /*
            //lookem up
            ITable tblFrom = (DatabaseTable)DataService.FindTable(fromTableName);
            if (tblFrom == null)
                tblFrom = DataService.FindTableByClassName(fromTableName);

            DatabaseTable tblTo = (DatabaseTable)DataService.FindTable(toTableName);
            if (tblTo == null)
                tblTo = DataService.FindTableByClassName(toTableName);
            
            DatabaseTableColumn fromCol = null;
            DatabaseTableColumn toCol = null;

            if (tblFrom != null) {
                fromCol = tblFrom.GetColumn(fromColumnName);

            }

            if (tblTo != null) {
                toCol = tblTo.GetColumn(toColumnName);
            }

            if (fromCol != null && toCol != null) {
                FromColumn = fromCol;
                ToColumn = toCol;
                Type = joinType;

            } else {
                throw new InvalidOperationException("Can't find the table/columns you're looking for");
            }
            */
        }
Exemplo n.º 12
0
 public JoinBlock(QueryBlock query, JoinType joinType, TableRef innerRef, StatementBlock on)
 {
     this.query = query;
     JoinType = joinType;
     InnerRef = innerRef;
     On = on;
 }
Exemplo n.º 13
0
 public JoinedTableExpression(IAliasedExpression left, IAliasedExpression right, JoinType joinType, TableAlias alias)
     : base(alias)
 {
     LeftTable = left;
     RightTable = right;
     JoinType = joinType;
 }
Exemplo n.º 14
0
 public Join(string rightTable, string rightTableAlias, string leftField, string rightField, JoinType type)
 {
     LeftField = leftField;
     RightTable = rightTable;
     RightTableAlias = rightTableAlias;
     RightField = rightField;
     Type = type;
 }
Exemplo n.º 15
0
 public JoinExpression(JoinType joinType, Expression left, Expression right, Expression condition)
     : base(DbExpressionType.Join, typeof(void))
 {
     this.joinType = joinType;
     this.left = left;
     this.right = right;
     this.condition = condition;
 }
Exemplo n.º 16
0
 public JoinedTableExpression(IAliasedExpression left, IAliasedExpression right, JoinType joinType, TableAlias alias, Evaluant.NLinq.Expressions.BinaryExpression on)
     : base(alias)
 {
     LeftTable = left;
     RightTable = right;
     JoinType = joinType;
     On = on;
 }
Exemplo n.º 17
0
 public QueryJoin(string modelField, IModel joinedModel, string joinedField, JoinType joinType, QExprGroup joinConditions)
 {
     ModelField = modelField;
     JoinedModel = joinedModel;
     JoinedField = joinedField;
     Type = joinType;
     JoinConditions = joinConditions;
 }
Exemplo n.º 18
0
Arquivo: Join.cs Projeto: eleooo/App
 /// <summary>
 /// Initializes a new instance of the <see cref="Join"/> class.
 /// </summary>
 /// <param name="from">From.</param>
 /// <param name="to">To.</param>
 /// <param name="joinType">Type of the join.</param>
 public Join(TableSchema.TableColumn from, TableSchema.TableColumn to, JoinType joinType,params string[] joinExpressions)
 {
     FromColumn = from;
     ToColumn = to;
     Type = joinType;
     if (joinExpressions != null && joinExpressions.Length > 0)
         JoinExpressions.AddRange(joinExpressions);
 }
Exemplo n.º 19
0
 public JoinClause(JoinType join, string toTableName, string toColumnName, Comparison @operator, string fromTableName, string fromColumnName)
 {
     this.JoinType = join;
     this.FromTable = fromTableName;
     this.FromColumn = fromColumnName;
     this.ComparisonOperator = @operator;
     this.ToTable = toTableName;
     this.ToColumn = toColumnName;
 }
Exemplo n.º 20
0
 public IEnumerable<string> GetJoinClauses(ObjectName mainTableName, IEnumerable<string> tableList, JoinType joinType = JoinType.Inner)
 {
     var tablePairs = tableList.Select(t => new ObjectName(mainTableName.Schema, t)).ToTuplePairs().ToList();
     foreach (var tablePair in tablePairs)
     {
         AddJoin(tablePair.Item1, tablePair.Item2);
     }
     return tablePairs.Select(tp => _done[tp.Item2]);
 }
Exemplo n.º 21
0
 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;
 }
Exemplo n.º 22
0
        internal JoinPart(JoinType joinType, SqlQueryExpression subQuery, SqlExpression onExpression)
        {
            if (subQuery == null)
                throw new ArgumentNullException("subQuery");

            OnExpression = onExpression;
            JoinType = joinType;
            SubQuery = subQuery;
        }
Exemplo n.º 23
0
        internal JoinPart(JoinType joinType, ObjectName tableName, SqlExpression onExpression)
        {
            if (tableName == null)
                throw new ArgumentNullException("tableName");

            OnExpression = onExpression;
            JoinType = joinType;
            TableName = tableName;
        }
Exemplo n.º 24
0
			public Join(ISessionFactoryImplementor factory, IAssociationType associationType, string alias, JoinType joinType,
			            string[] lhsColumns)
			{
				this.associationType = associationType;
				this.joinable = associationType.GetAssociatedJoinable(factory);
				this.alias = alias;
				this.joinType = joinType;
				this.lhsColumns = lhsColumns;
			}
 public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns,
                              JoinType joinType)
 {
     if (joinType == JoinType.FullJoin)
     {
         throw new AssertionFailure("Cache does not support full outer joins");
     }
     base.AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
 }
Exemplo n.º 26
0
 public JoinExpression(Expression left, Expression right, JoinType type, Expression filter)
     : this()
 {
     SetArgument("left", left);
     SetArgument("right", right);
     SetArgument("type", type);
     if (filter != null)
         SetArgument("filter", filter);
 }
Exemplo n.º 27
0
 public WhereClause(JoinType joinType, params IWhere[] criteria)
 {
     if (criteria == null || criteria.Length < 2)
     {
         throw new Exception("A where clause can only be created from two or more components.");
     }
     JoinType = joinType;
     Add(criteria);
 }
Exemplo n.º 28
0
 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;
 }
Exemplo n.º 29
0
 public IEnumerable<string> GetJoinClauses(ObjectName mainTableName, IEnumerable<ObjectReference> references, JoinType joinType = JoinType.Inner)
 {
     _done.AddOrUpdate(mainTableName, string.Empty, (s, o) => string.Empty);
     var tablePairs = GetTableNames(references, mainTableName.Schema).Distinct().ToList();
     foreach (var tablePair in tablePairs)
     {
         AddJoin(tablePair.Item1, tablePair.Item2, joinType);
     }
     return tablePairs.Select(tp => _done[tp.Item2]).Distinct();
 }
Exemplo n.º 30
0
        public IdentifierNode(string[] parts, JoinType[] joins, Token token, int tokenIndex) : base(token, tokenIndex)
        {
            if (joins.Length != parts.Length - 1)
            {
                throw new InternalCompilerException("Error constructing IdentifierNode: Part count must be one greater than join count.");
            }

            Joins = joins;
            Parts = parts;
        }
Exemplo n.º 31
0
 public WhereClause(JoinType joinType)
 {
     JoinType = joinType;
 }
        public Application_PeopleQuery <Application_DeliveryMethodQuery <K, T>, T> JoinApplication_People(JoinType joinType = JoinType.Inner, bool preloadEntities = false)
        {
            var joinedQuery = new Application_PeopleQuery <Application_DeliveryMethodQuery <K, T>, T>(Db);

            return(Join(joinedQuery, string.Concat(joinType.GetJoinString(), " [Application].[People] AS {1} {0} ON", "{2}.[LastEditedBy] = {1}.[PersonID]"), o => ((Application_DeliveryMethod)o)?.Application_People, (e, fv, ppe) =>
            {
                var child = (Application_People)ppe(QueryHelpers.Fill <Application_People>(null, fv));
                if (e != null)
                {
                    ((Application_DeliveryMethod)e).Application_People = child;
                }

                return child;
            }

                        , typeof(Application_People), preloadEntities));
        }
        public Purchasing_SupplierQuery <Application_DeliveryMethodQuery <K, T>, T> JoinPurchasing_Suppliers(JoinType joinType = JoinType.Inner, bool attach = false)
        {
            var joinedQuery = new Purchasing_SupplierQuery <Application_DeliveryMethodQuery <K, T>, T>(Db);

            return(JoinSet(() => new Purchasing_SupplierTableQuery <Purchasing_Supplier>(Db), joinedQuery, string.Concat(joinType.GetJoinString(), " [Purchasing].[Suppliers] AS {1} {0} ON", "{2}.[DeliveryMethodID] = {1}.[DeliveryMethodID]"), (p, ids) => ((Purchasing_SupplierWrapper)p).Id.In(ids.Select(id => (System.Int32)id)), (o, v) => ((Application_DeliveryMethod)o).Purchasing_Suppliers.Attach(v.Cast <Purchasing_Supplier>()), p => (long)((Purchasing_Supplier)p).DeliveryMethodID, attach));
        }
Exemplo n.º 34
0
 /// <summary>
 /// Join
 /// </summary>
 /// <param name="sqlable"></param>
 /// <param name="shortName">表名简写</param>
 /// <param name="leftFiled">join左边连接字段</param>
 /// <param name="RightFiled">join右边连接字段</param>
 /// <param name="type">join类型</param>
 /// <returns></returns>
 public static Sqlable Join <T>(this Sqlable sqlable, string shortName, string leftFiled, string RightFiled, JoinType type)
 {
     Check.ArgumentNullException(sqlable.Sql, "语法错误,正确用法:sqlable.Form(“table”).Join");
     sqlable.Sql.AppendFormat(" {0} JOIN {1} {2}  {3} ON  {4} = {5} ", type.ToString(), typeof(T).Name.GetTranslationSqlName(), shortName, sqlable.DB.IsNoLock.GetLockString(), leftFiled, RightFiled);
     return(sqlable);
 }
Exemplo n.º 35
0
 public new IQueryProviderWithIncludes <T> Include <T2>(Expression <Func <T, T2> > expression, string tableAlias, JoinType joinType = JoinType.Left) where T2 : class
 {
     return((IQueryProviderWithIncludes <T>)base.Include(expression, tableAlias, joinType));
 }
Exemplo n.º 36
0
 public static SelectBuilder Join <TEntity1, TEntity2>(this SelectBuilder builder,
                                                       JoinType joinType, Expression <Func <TEntity1, TEntity2, bool> > condition)
 {
     return(builder.Join(joinType, builder.GetNextTableAlias(), condition));
 }
Exemplo n.º 37
0
        public Sales_OrderLineQuery <Warehouse_PackageTypeQuery <K, T>, T> JoinSales_OrderLines(JoinType joinType = JoinType.Inner, bool attach = false)
        {
            var joinedQuery = new Sales_OrderLineQuery <Warehouse_PackageTypeQuery <K, T>, T>(Db);

            return(JoinSet(() => new Sales_OrderLineTableQuery <Sales_OrderLine>(Db), joinedQuery, string.Concat(joinType.GetJoinString(), " [Sales].[OrderLines] AS {1} {0} ON", "{2}.[PackageTypeID] = {1}.[PackageTypeID]"), (p, ids) => ((Sales_OrderLineWrapper)p).Id.In(ids.Select(id => (System.Int32)id)), (o, v) => ((Warehouse_PackageType)o).Sales_OrderLines.Attach(v.Cast <Sales_OrderLine>()), p => (long)((Sales_OrderLine)p).PackageTypeID, attach));
        }
Exemplo n.º 38
0
        public Warehouse_StockItemQuery <Warehouse_PackageTypeQuery <K, T>, T> JoinPackageTypes(JoinType joinType = JoinType.Inner, bool attach = false)
        {
            var joinedQuery = new Warehouse_StockItemQuery <Warehouse_PackageTypeQuery <K, T>, T>(Db);

            return(JoinSet(() => new Warehouse_StockItemTableQuery <Warehouse_StockItem>(Db), joinedQuery, string.Concat(joinType.GetJoinString(), " [Warehouse].[StockItems] AS {1} {0} ON", "{2}.[PackageTypeID] = {1}.[UnitPackageID]"), (p, ids) => ((Warehouse_StockItemWrapper)p).Id.In(ids.Select(id => (System.Int32)id)), (o, v) => ((Warehouse_PackageType)o).PackageTypes.Attach(v.Cast <Warehouse_StockItem>()), p => (long)((Warehouse_StockItem)p).UnitPackageID, attach));
        }
Exemplo n.º 39
0
 public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
                              string on)
 {
     AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
     AddCondition(on);
 }
Exemplo n.º 40
0
        private IAsyncQueryProviderWithIncludes <T> QueryProviderWithIncludes(Expression expression, string tableAlias, JoinType joinType)
        {
            var joinExpressions = _buildComplexSql.GetJoinExpressions(expression, tableAlias, joinType);

            foreach (var joinExpression in joinExpressions)
            {
                _joinSqlExpressions[joinExpression.Key] = joinExpression.Value;
            }

            return(this);
        }
Exemplo n.º 41
0
 void SetImpliedJoinType(int joinType)
 {
     _impliedJoinType = JoinProcessor.ToHibernateJoinType(joinType);
 }
Exemplo n.º 42
0
 public IAsyncQueryProviderWithIncludes <T> Include <T2>(Expression <Func <T, T2> > expression, JoinType joinType = JoinType.Left) where T2 : class
 {
     return(QueryProviderWithIncludes(expression, null, joinType));
 }
Exemplo n.º 43
0
        /// <summary>
        /// 联表查询
        /// </summary>
        /// <typeparam name="T">第一个表的对象</typeparam>
        /// <typeparam name="T2">联接的表对象</typeparam>
        /// <param name="queryable"></param>
        /// <param name="expression">表达示</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Queryable <T> JoinTable <T, T2, T3>(this Queryable <T> queryable, Expression <Func <T, T2, T3, object> > expression, JoinType type = JoinType.LEFT)
        {
            ResolveExpress re = new ResolveExpress();

            queryable.WhereIndex = queryable.WhereIndex + 100;
            re.Type = ResolveExpressType.nT;
            var exLeftStr   = Regex.Match(expression.ToString(), @"\((.+?)\).+").Groups[1].Value;
            var exLeftArray = exLeftStr.Split(',');
            var shortName1  = exLeftArray[1];
            var shortName2  = exLeftArray[2];

            re.ResolveExpression(re, expression);
            string joinTableName = type.ToString();
            string joinStr       = string.Format(" {0} JOIN {1} {2} ON {3}  ",
                                                 /*0*/ queryable.JoinTable.Count == 0 ? (" " + shortName1 + " " + joinTableName) : joinTableName.ToString(),
                                                 /*1*/ typeof(T3).Name,
                                                 /*2*/ shortName2,
                                                 /*3*/ re.SqlWhere.Trim().TrimStart('A').TrimStart('N').TrimStart('D')
                                                 );

            queryable.JoinTable.Add(joinStr);
            queryable.Params.AddRange(re.Paras);
            return(queryable);
        }
Exemplo n.º 44
0
 public new IQueryProvider <T> IncludeMany(Expression <Func <T, IList> > expression, JoinType joinType = JoinType.Left)
 {
     return((IQueryProvider <T>)base.IncludeMany(expression, joinType));
 }
Exemplo n.º 45
0
 /// <summary>
 /// Returns true if any components of this query are of a different join type than the test
 /// </summary>
 public bool IsCompoundFor(JoinType joinType)
 {
     return(Count > 1 &&
            (JoinType != joinType ||
             CriteriaList.Any(item => item is WhereClause && ((WhereClause)item).JoinType != JoinType)));
 }
Exemplo n.º 46
0
 public IAsyncQueryProvider <T> IncludeMany(Expression <Func <T, IList> > expression, JoinType joinType = JoinType.Left)
 {
     _listExpression = expression;
     return(QueryProviderWithIncludes(expression, null, joinType));
 }
Exemplo n.º 47
0
        void CreateFromJoinElement(
            IASTNode path,
            IASTNode alias,
            int joinType,
            IASTNode fetchNode,
            IASTNode propertyFetch,
            IASTNode with)
        {
            bool fetch = fetchNode != null;

            if (fetch && IsSubQuery)
            {
                throw new QueryException("fetch not allowed in subquery from-elements");
            }
            // The path AST should be a DotNode, and it should have been evaluated already.
            if (path.Type != DOT)
            {
                throw new SemanticException("Path expected for join!");
            }

            DotNode dot = ( DotNode )path;
            //JoinType hibernateJoinType = JoinProcessor.ToHibernateJoinType( joinType );
            JoinType hibernateJoinType = _impliedJoinType;

            dot.JoinType = hibernateJoinType;                   // Tell the dot node about the join type.
            dot.Fetch    = fetch;

            // Generate an explicit join for the root dot node.   The implied joins will be collected and passed up
            // to the root dot node.
            dot.Resolve(true, false, alias == null ? null : alias.Text);

            FromElement fromElement;

            if (dot.DataType != null && dot.DataType.IsComponentType)
            {
                var factory = new FromElementFactory(CurrentFromClause, dot.GetLhs().FromElement, dot.PropertyPath, alias == null ? null : alias.Text, null, false);
                fromElement = factory.CreateComponentJoin((ComponentType)dot.DataType);
            }
            else
            {
                fromElement = dot.GetImpliedJoin();
                if (fromElement == null)
                {
                    throw new InvalidPathException("Invalid join: " + dot.Path);
                }
                fromElement.SetAllPropertyFetch(propertyFetch != null);

                if (with != null)
                {
                    if (fetch)
                    {
                        throw new SemanticException("with-clause not allowed on fetched associations; use filters");
                    }

                    HandleWithFragment(fromElement, with);
                }
            }

            if (log.IsDebugEnabled())
            {
                log.Debug("createFromJoinElement() : {0}", _printer.ShowAsString(fromElement, "-- join tree --"));
            }
        }
Exemplo n.º 48
0
    /// <summary>
    /// Joins the passed in DataTables on the colToJoinOn.
    /// <para>Returns an appropriate DataTable with zero rows if the colToJoinOn does not exist in both tables.</para>
    /// </summary>
    /// <param name="dtblLeft"></param>
    /// <param name="dtblRight"></param>
    /// <param name="colToJoinOn"></param>
    /// <param name="joinType"></param>
    /// <returns></returns>
    /// <remarks>
    /// <para>http://stackoverflow.com/questions/2379747/create-combined-datatable-from-two-datatables-joined-with-linq-c-sharp?rq=1</para>
    /// <para>http://msdn.microsoft.com/en-us/library/vstudio/bb397895.aspx</para>
    /// <para>http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html</para>
    /// <para>http://stackoverflow.com/questions/406294/left-join-and-left-outer-join-in-sql-server</para>
    /// </remarks>
    public static DataTable JoinTwoDataTablesOnOneColumn(DataTable dtblLeft, DataTable dtblRight, string colToJoinOn, JoinType joinType)
    {
        //Change column name to a temp name so the LINQ for getting row data will work properly.
        string strTempColName = colToJoinOn + "_2";

        if (dtblRight.Columns.Contains(colToJoinOn))
        {
            dtblRight.Columns[colToJoinOn].ColumnName = strTempColName;
        }
        //Get columns from dtblA
        DataTable dtblResult = dtblLeft.Clone();
        //Get columns from dtblB
        var dt2Columns = dtblRight.Columns.OfType <DataColumn>().Select(dc => new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping));
        //Get columns from dtblB that are not in dtblA
        var dt2FinalColumns = from dc in dt2Columns.AsEnumerable()
                              where !dtblResult.Columns.Contains(dc.ColumnName)
                              select dc;

        //Add the rest of the columns to dtblResult
        dtblResult.Columns.AddRange(dt2FinalColumns.ToArray());
        //No reason to continue if the colToJoinOn does not exist in both DataTables.
        if (!dtblLeft.Columns.Contains(colToJoinOn) || (!dtblRight.Columns.Contains(colToJoinOn) && !dtblRight.Columns.Contains(strTempColName)))
        {
            if (!dtblResult.Columns.Contains(colToJoinOn))
            {
                dtblResult.Columns.Add(colToJoinOn);
            }
            return(dtblResult);
        }
        switch (joinType)
        {
        default:
        case JoinType.Inner:
            #region Inner
            //get row data
            //To use the DataTable.AsEnumerable() extension method you need to add a reference to the System.Data.DataSetExtension assembly in your project.
            var rowDataLeftInner = from rowLeft in dtblLeft.AsEnumerable()
                                   join rowRight in dtblRight.AsEnumerable() on rowLeft[colToJoinOn] equals rowRight[strTempColName]
                                   select rowLeft.ItemArray.Concat(rowRight.ItemArray).ToArray();

            //Add row data to dtblResult
            foreach (object[] values in rowDataLeftInner)
            {
                dtblResult.Rows.Add(values);
            }
            #endregion
            break;

        case JoinType.Left:
            #region Left
            var rowDataLeftOuter = from rowLeft in dtblLeft.AsEnumerable()
                                   join rowRight in dtblRight.AsEnumerable() on rowLeft[colToJoinOn] equals rowRight[strTempColName] into gj
                                   from subRight in gj.DefaultIfEmpty()
                                   select rowLeft.ItemArray.Concat((subRight == null)?(dtblRight.NewRow().ItemArray) : subRight.ItemArray).ToArray();

            //Add row data to dtblResult
            foreach (object[] values in rowDataLeftOuter)
            {
                dtblResult.Rows.Add(values);
            }

            #endregion
            break;
        }
        //Change column name back to original
        dtblRight.Columns[strTempColName].ColumnName = colToJoinOn;
        //Remove extra column from result
        dtblResult.Columns.Remove(strTempColName);
        return(dtblResult);
    }
Exemplo n.º 49
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6, bool> > onExpression, JoinType joinType = JoinType.Left, string tableName = null, bool noLock = true)
            : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");

            var t6 = new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T6",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity6>(),
                On     = onExpression,
                NoLock = noLock
            };

            t6.TableName = tableName.NotNull() ? tableName : t6.EntityDescriptor.TableName;
            QueryBody.JoinDescriptors.Add(t6);

            QueryBody.WhereDelegateType = typeof(Func <, , , , , ,>).MakeGenericType(typeof(TEntity), typeof(TEntity2), typeof(TEntity3), typeof(TEntity4), typeof(TEntity5), typeof(TEntity6), typeof(bool));
        }
Exemplo n.º 50
0
 public static SelectBuilder Join <TEntity1, TEntity2, TJoin>(this SelectBuilder builder,
                                                              JoinType joinType, string alias, Expression <Func <TEntity1, TEntity2, TJoin, bool> > condition)
 {
     return(builder.Join(joinType, alias, typeof(TJoin),
                         new[] { typeof(TEntity1), typeof(TEntity2) }, condition));
 }
Exemplo n.º 51
0
 public Join(JoinType joinType, Table table, SourceExpression leftColumn, SourceExpression rightColumn)
 {
     this.JoinType = joinType;
     this.Table    = table;
     this.Conditions.Add(new Condition(leftColumn, SqlOperator.Equals, rightColumn));
 }
Exemplo n.º 52
0
        public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType)
        {
            AddCrossJoin(tableName, alias);

            for (int j = 0; j < fkColumns.Length; j++)
            {
                //full joins are not supported.. yet!
                if (joinType == JoinType.FullJoin)
                {
                    throw new InvalidOperationException("full joins are not supported yet");
                }

                afterWhere.Add(" and " + fkColumns[j]);

                if (joinType == JoinType.LeftOuterJoin)
                {
                    afterWhere.Add("*");
                }
                afterWhere.Add("=");
                if (joinType == JoinType.RightOuterJoin)
                {
                    afterWhere.Add("*");
                }

                afterWhere.Add(alias + StringHelper.Dot + pkColumns[j]);
            }
        }
Exemplo n.º 53
0
 public Join(JoinType joinType, StatementPart right, ConditionExpression condition)
 {
     this.JoinType = joinType;
     this.Table    = right;
     this.Conditions.Add(condition);
 }
Exemplo n.º 54
0
 internal void AddJoin(JoinSide left, JoinSide right, JoinType type)
 {
     Join = new JoinDefinition(left, right, type);
 }