Exemple #1
0
 public void AppendJoin(JoinPredicate predicate)
 {
     if (!((ICommandBuilder)this).JoinPredicates.Contains(predicate))
     {
         ((ICommandBuilder)this).JoinPredicates.Add(predicate);
     }
 }
Exemple #2
0
        private void WriteWhereJoinPredicates(DbTextWriter writer, IEnumerable <JoinPredicate> predicates)
        {
            int i = 0;

            foreach (JoinPredicate predicate in predicates)
            {
                if (predicate.OrToPreviousGroup)
                {
                    OnWriteOr(writer);
                }
                else if (i++ >= 1)
                {
                    OnWriteAnd(writer);
                }

                if (predicate.IsGroup)
                {
                    WriteBeginGroup(writer);
                    for (JoinPredicate current = predicate; current != null; current = current.NextInGroup)
                    {
                        WriteJoinPredicate(writer, current);
                    }
                }
                else
                {
                    WriteJoinPredicate(writer, predicate);
                }
            }
        }
Exemple #3
0
        public void TwoDuplicatePredicateJoinFail()
        {
            EntitySet <Employee> query = Session.Employees;

            JoinPredicate joinPredicate1 = new JoinPredicate(Employee.Columns.BusinessEntityId, Comparison.Greater, Customer.Columns.CustomerId);

            // Expected: Cannot add joinPredicate1 twice.
            query.Join <Customer>(joinPredicate1 | joinPredicate1);
        }
Exemple #4
0
        private JoinPredicate ToExplicitJoinPredicate()
        {
            if (Value != null && !IsJoinPredicate)
            {
                throw new InvalidOperationException();
            }

            JoinPredicate predicate = new JoinPredicate(Column, Comparison, (IQueryableColumn)Value);

            predicate.OrNextPredicate = OrNextPredicate;
            predicate.NextInGroup     = NextInGroup;

            return(predicate);
        }
Exemple #5
0
        public JoinPredicate AsJoin()
        {
            if (!IsJoinPredicate)
            {
                throw new InvalidOperationException();
            }

            JoinPredicate predicate = new JoinPredicate(Column, Comparison, (IQueryableColumn)Value);

            predicate.OrNextPredicate = OrNextPredicate;
            predicate.NextInGroup     = NextInGroup == null ? null : NextInGroup.ToExplicitJoinPredicate();

            return(predicate);
        }
Exemple #6
0
        public virtual void WritePredicate(JoinPredicate current, string comparisonOperator)
        {
            string fromColumnName = FormatPredicateColumnName(current.FromColumn);
            string toColumnName   = FormatPredicateColumnName(current.ToColumn);

            if (Compare.IsNullOrEmpty(toColumnName))
            {
                Write(Formats.NullComparisonPredicateFormat, fromColumnName, comparisonOperator);
            }
            else
            {
                Write(Formats.DefaultPredicateFormat, fromColumnName, comparisonOperator, toColumnName);
            }
        }
Exemple #7
0
        private void WriteJoinPredicate(DbTextWriter writer, JoinPredicate current)
        {
            writer.WritePredicate(current, GetComparisonOperator(current.Comparison, current.ToColumn));

            if (current.NextInGroup == null)
            {
                WriteEndGroup(writer);
            }

            if (current.NextInGroup != null && current.OrNextPredicate)
            {
                OnWriteOr(writer);
            }
            else if (current.NextInGroup != null)
            {
                OnWriteAnd(writer);
            }
        }
Exemple #8
0
        public void ManualPredicateJoin()
        {
            const string expected = "SELECT * FROM [HumanResources].[Employee] _t0, [Sales].[Customer] _t1 " +
                                    "WHERE (_t0.[BusinessEntityID] > _t1.[CustomerID] " +
                                    "OR _t0.[BusinessEntityID] < _t1.[CustomerID]) " +
                                    "AND (_t0.[HireDate] = @_p0 " +
                                    "AND _t1.[CustomerID] = @_p1)";

            EntitySet <Employee> query = Session.Employees;

            JoinPredicate joinPredicate1 = new JoinPredicate(Employee.Columns.BusinessEntityId, Comparison.Greater, Customer.Columns.CustomerId);
            JoinPredicate joinPredicate2 = Employee.Columns.BusinessEntityId < Customer.Columns.CustomerId;

            query.Join <Customer>(joinPredicate1 | joinPredicate2);
            query.Where((Employee.Columns.HireDate == DateTime.Now) & (Customer.Columns.CustomerId == 1));

            AssertCommandTextSame(expected, query);
            AssertParamCountSame(query, 2);
        }
Exemple #9
0
        private void WriteJoinPredicates(DbTextWriter writer, IEnumerable <JoinPredicate> predicates)
        {
            foreach (JoinPredicate predicate in predicates)
            {
                writer.Write(" LEFT JOIN {0} ON ", "[" + predicate.ToColumn.Table.Owner + "].[" + predicate.ToColumn.Table.Name + "] " + writer.GetTableAlias(predicate.ToColumn.Table));

                if (predicate.IsGroup)
                {
                    WriteBeginGroup(writer);
                    for (JoinPredicate current = predicate; current != null; current = current.NextInGroup)
                    {
                        WriteJoinPredicate(writer, current);
                    }
                }
                else
                {
                    WriteJoinPredicate(writer, predicate);
                }
            }
        }
Exemple #10
0
        public void AppendSelect(IQueryableColumn selectColumn)
        {
            string currentCulture = CultureInfo.CurrentCulture.Name;

            if (!session.UseDefaultLocale && session.DefaultLocale != currentCulture && session.IsLanguageSupported(currentCulture))
            {
                IQueryableColumn localizedColumn = selectColumn.LocalizedColumn;
                if (localizedColumn != null)
                {
                    localizedColumn = localizedColumn.As(selectColumn.Alias);
                    ColumnPredicate localizePredicate = (localizedColumn.Table.FindColumn("Locale") == currentCulture) | (localizedColumn.Table.FindColumn("Locale") == null);
                    if (!((ICommandBuilder)this).WherePredicates.Contains(localizePredicate))
                    {
                        ((ICommandBuilder)this).WherePredicates.Add(localizePredicate);
                    }
                    localizedColumn.LocalizeFallbackColumn = selectColumn;
                    Columns.Add(localizedColumn);

                    foreach (QueryColumn primaryKey in selectColumn.Table.PrimaryKey)
                    {
                        JoinPredicate joinPredicate = primaryKey == localizedColumn.Table.FindColumn(primaryKey.Name);

                        if (!LocalizedJoinPredicates.Contains(joinPredicate))
                        {
                            LocalizedJoinPredicates.Add(joinPredicate);
                        }
                    }

                    JoinInWhereClause = false;
                    return;
                }
            }

            AppendFrom(selectColumn.Table);
            Columns.Add(selectColumn);
        }