Пример #1
0
        internal bool IsInnerJoin(DB3 firstTable)
        {
            if (IsRefTable(firstTable))
            {
                return(true);
            }

            return(!DbMapping.GetColumnMap(FKColumns[0]).IsNullable);
        }
Пример #2
0
        internal Column[] GetFK(int alias)
        {
            List <Column> columns = new List <Column>();

            foreach (var columnID in FKColumns)
            {
                columns.Add(Designer.Identifier(alias.ToString(), DbMapping.GetColumnMap(columnID).Name.Part1));
            }
            return(columns.ToArray());
        }
Пример #3
0
        internal string BuildRelation(DB3 table1, string alias1, string alias2)
        {
            string aliasA, aliasB;

            if (table1.TableID.Equals(ID.TableID) &&
                !IsSelfRelation)
            {
                aliasA = alias1;
                aliasB = alias2;
            }
            else
            {
                aliasA = alias2;
                aliasB = alias1;
            }

            var sql = Text.GenerateSql(70);

            for (int i = 0; i < FKColumns.Count(); ++i)
            {
                if (i > 0)
                {
                    sql.Append(Text._And_);
                }

                var columnA = DbMapping.GetColumnMap(FKColumns[i]);
                var columnB = DbMapping.GetColumnMap(RefColumns[i]);

                sql
                .AppendFormat("[{0}].{1} = [{2}].{3}",
                              aliasA, columnA.Name.Sql,
                              aliasB, columnB.Name.Sql);
            }

            return(sql.ToString());
        }
Пример #4
0
        // When a subject S2 of a predicate is a single node without the chaining and the predicates (+expression)
        // and it represents a simple foreign key (with a single column) then it is translated as an expression
        // where FK attribute is checked by NOT NULL operator.
        //   note:
        //     If a FK is NOT NULLABLE then the .Where method is omitted.
        //   returns:
        //     True if a simple foreign key has been processed.
        internal static bool ProcessSimpleForeignKey(
            DbNode currentNode,
            DbNode innerNode,
            Predicate predicate,
            Link link,
            ref Chainer query)
        {
            if (!(
                    innerNode.IsLast &&                      // subject is a single non-chained node
                    !((IPredicate)innerNode).HasPredicate && // without a predicate
                    !innerNode.HasExpression                 // without expression
                    ))
            {
                return(false);
            }

            var foreignKey = innerNode.GetFK();
            var relation   = link.TryGetRelation(foreignKey);

            // is relation many-to-one?
            if (relation.IsRefTable(currentNode.SynonymOrThis.NodeID))
            {
                return(false);
            }

            // is simple foreign key?
            if (relation.FKColumns.Count() > 1)
            {
                return(false);
            }

            // assure that foreign key column is given
            if (foreignKey.IsDefault)
            {
                foreignKey = relation.ForeignKey;
            }

            var fk     = DbMapping.GetColumnMap(foreignKey);
            var column = String.Format("{0}.{1}", predicate.Subject.Index, fk.Name.Part1);

            // prepare expression
            Expression expression = column.IsNotNull();

            if (!fk.IsNullable)
            {
                expression = "1=1";
            }

            if (query is ConditionChainer)
            {
                if (predicate.LogicalOperator == LogicalOperator.Or)
                {
                    query = ((ConditionChainer)query)
                            .OrWhere(expression, predicate.Sign, predicate.PredicateGroup);
                }
                else
                {
                    query = ((ConditionChainer)query)
                            .AndWhere(expression, predicate.Sign, predicate.PredicateGroup);
                }
            }
            else
            {
                query = ((IWhere)query)
                        .Where(expression, predicate.Sign, predicate.PredicateGroup);
            }

            return(true);
        }