Esempio n. 1
0
        private void CreateJoin <T>(string fromColumnName, string toColumnName, Join.JoinType type)
        {
            //see if we can find the table
            var toTable = _provider.FindOrCreateTable(typeof(T));

            //the assumption here is that the FromTable[0] is the table to join from
            if (FromTables.Count == 0)
            {
                throw new InvalidOperationException("Can't join if there's no table to join to - make sure to use From() before InnerJoin");
            }

            if (toTable == null)
            {
                throw new InvalidOperationException("Can't find the table for this type. Try using the Column instead");
            }

            var fromColumn = FromTables[0].GetColumn(fromColumnName);

            if (fromColumn == null)
            {
                throw new InvalidOperationException("Don't know which column to join to - can't find column " + fromColumnName + " in table " + FromTables[0].Name);
            }

            var toColumn = toTable.GetColumn(toColumnName);

            if (toColumn == null)
            {
                throw new InvalidOperationException("Don't know which column to join to - can't find column " + toColumnName + " in table " + toTable.Name);
            }

            CreateJoin(fromColumn, toColumn, Join.JoinType.Inner);
        }
Esempio n. 2
0
        ToDBCommand Join(string table, Action <ConditionBuilder> where, Join.JoinType joinType)
        {
            ConditionBuilder whereBuilder = new ConditionBuilder();

            where (whereBuilder);
            Joins.Add(new Join {
                Table = new TableItem {
                    Item = table
                }, On = whereBuilder, TypeOfJoin = joinType
            });
            return(this);
        }
Esempio n. 3
0
        private void CreateJoin(IColumn fromColumn, IColumn toColumn, Join.JoinType type)
        {
            Join j = new Join(toColumn, fromColumn, type);

            Joins.Add(j);

            //add the tables to the From collection
            if (!FromTables.Contains(toColumn.Table))
            {
                FromTables.Add(toColumn.Table);
            }
        }
Esempio n. 4
0
        private void CreateJoin <T>(string fromColumnName, string toColumnName, Join.JoinType type)
        {
            //see if we can find the table
            var toTable = _provider.FindOrCreateTable(typeof(T));

            //the assumption here is that the FromTable[0] is the table to join from
            if (FromTables.Count == 0)
            {
                throw new InvalidOperationException("Can't join if there's no table to join to - make sure to use From() before InnerJoin");
            }

            if (toTable == null)
            {
                throw new InvalidOperationException("Can't find the table for this type. Try using the Column instead");
            }

            var fromColumn = FromTables[0].GetColumn(fromColumnName);

            if (fromColumn == null)
            {
                throw new InvalidOperationException("Don't know which column to join to - can't find column " + fromColumnName + " in table " + FromTables[0].Name);
            }

            var toColumn = toTable.GetColumn(toColumnName);

            if (toColumn == null)
            {
                throw new InvalidOperationException("Don't know which column to join to - can't find column " + toColumnName + " in table " + toTable.Name);
            }

            /*
             * 修 改 人:Empty(AllEmpty)
             * QQ    群:327360708
             * 博客地址:http://www.cnblogs.com/EmptyFS/
             * 修改时间:2013-09-23
             * 修改说明:本函数在调用CreateJoin函数时,使用的是Join.JoinType.LeftInner参数,并没有使用传进来的参数type
             *			 本次修改将它改为type
             *********************************************/
            CreateJoin(fromColumn, toColumn, type);
        }
Esempio n. 5
0
        private void CreateJoin <T>(Join.JoinType type)
        {
            //see if we can find the table
            var toTable = _provider.FindOrCreateTable(typeof(T));

            if (toTable == null)
            {
                throw new InvalidOperationException("Can't find the table for this type. Try using the Column instead");
            }

            //the assumption here is that the FromTable[0] is the table to join from
            if (FromTables.Count == 0)
            {
                throw new InvalidOperationException("Can't join if there's no table to join to - make sure to use From() before InnerJoin");
            }

            //the "from" table is a bit tricky
            //if this is a multi-join, then we need to pull from the very last table in the Join list

            ITable fromTable = Joins.Count > 0 ? Joins[Joins.Count - 1].FromColumn.Table : FromTables[0];

            //first effort, match the name of the fromTable PK to the toTable
            var fromColumn = fromTable.PrimaryKey;

            //find the From table's PK in the other table
            var toColumn = toTable.GetColumn(fromColumn.Name);

            if (toColumn == null)
            {
                //second effort - reverse the lookup and match the PK of the toTable to the fromTable
                toColumn   = toTable.PrimaryKey;
                fromColumn = fromTable.GetColumn(toColumn.Name);
            }

            if (toColumn == null)
            {
                //match the first matching pair
                foreach (var col in fromTable.Columns)
                {
                    fromColumn = col;
                    toColumn   = toTable.GetColumn(fromColumn.Name);

                    if (toColumn != null)
                    {
                        break;
                    }
                }
            }

            //still null? keep going - reverse the last search
            if (toColumn == null)
            {
                //match the first matching pair
                foreach (var col in toTable.Columns)
                {
                    fromColumn = col;
                    toColumn   = toTable.GetColumn(fromColumn.Name);

                    if (toColumn != null)
                    {
                        break;
                    }
                }
            }

            //OK - give up
            if (toColumn == null)
            {
                throw new InvalidOperationException("Don't know which column to join to - tried to join based on Primary Key (" + fromColumn.Name + ") but couldn't find a match");
            }

            CreateJoin(fromColumn, toColumn, type);
        }