Пример #1
0
        public static Expression In(Expression element, object[] values, bool isPostgres)
        {
            var nominate = DbExpressionNominator.FullNominate(element) !;

            if (nominate.RemoveUnNullify() is ToDayOfWeekExpression dowe)
            {
                if (isPostgres)
                {
                    var sqlWeekDays = values.Cast <DayOfWeek>()
                                      .Select(a => (object)(int)a)
                                      .ToArray();
                    return(InExpression.FromValues(dowe.Expression, sqlWeekDays));
                }
                else
                {
                    byte dateFirs    = ((SqlServerConnector)Connector.Current).DateFirst;
                    var  sqlWeekDays = values.Cast <DayOfWeek>()
                                       .Select(a => (object)ToDayOfWeekExpression.ToSqlWeekDay(a, dateFirs))
                                       .ToArray();
                    return(InExpression.FromValues(dowe.Expression, sqlWeekDays));
                }
            }
            else
            {
                return(InExpression.FromValues(nominate, values));
            }
        }
Пример #2
0
        static internal ProjectedColumns ProjectColumns(Expression projector, Alias newAlias, bool isGroupKey = false, bool selectTrivialColumns = false)
        {
            var candidates = DbExpressionNominator.Nominate(projector, out Expression newProj, isGroupKey: isGroupKey);

            ColumnProjector cp = new ColumnProjector(candidates, newAlias, selectTrivialColumns);

            Expression e = cp.Visit(newProj);

            return(new ProjectedColumns(e, cp.generator.Columns.NotNull().ToReadOnly()));
        }
Пример #3
0
        public static Expression InPrimaryKey(Expression element, PrimaryKey[] values)
        {
            var cleanValues = values.Select(a => a.Object).ToArray();

            var cleanElement = SmartEqualizer.UnwrapPrimaryKey(element);

            if (cleanElement == NewId)
            {
                return(False);
            }

            return(InExpression.FromValues(DbExpressionNominator.FullNominate(cleanElement), cleanValues));
        }
Пример #4
0
        public static Expression In(Expression element, object[] values)
        {
            var nominate = DbExpressionNominator.FullNominate(element) !;

            if (nominate is ToDayOfWeekExpression dowe)
            {
                byte dateFirs    = ToDayOfWeekExpression.DateFirst.Value.Item1;
                var  sqlWeekDays = values.Cast <DayOfWeek>()
                                   .Select(a => (object)ToDayOfWeekExpression.ToSqlWeekDay(a, dateFirs))
                                   .ToArray();

                return(InExpression.FromValues(dowe.Expression, sqlWeekDays));
            }
            else
            {
                return(InExpression.FromValues(nominate, values));
            }
        }
Пример #5
0
        public static Expression InPrimaryKey(Expression element, PrimaryKey[] values)
        {
            var cleanValues = values.Select(a => a.Object).ToArray();

            var cleanElement = SmartEqualizer.UnwrapPrimaryKey(element);

            if (cleanElement == NewId)
            {
                return(False);
            }

            cleanElement = DbExpressionNominator.FullNominate(cleanElement) !;

            if (cleanElement.Type == typeof(string))
            {
                return(InExpression.FromValues(cleanElement, cleanValues.Select(a => (object)a.ToString() !).ToArray()));
            }
            else
            {
                return(InExpression.FromValues(cleanElement, cleanValues));
            }
        }
Пример #6
0
        static Expression EntityIn(Expression newItem, Dictionary <Type, PrimaryKey[]> entityIDs)
        {
            if (newItem is EntityExpression ee)
            {
                return(InPrimaryKey(ee.ExternalId, entityIDs.TryGetC(ee.Type) ?? new PrimaryKey[0]));
            }

            if (newItem is ImplementedByExpression ib)
            {
                return(ib.Implementations.JoinDictionary(entityIDs,
                                                         (t, f, values) => Expression.And(DbExpressionNominator.FullNominate(NotEqualToNull(f.ExternalId)), InPrimaryKey(f.ExternalId, values)))
                       .Values.AggregateOr());
            }

            if (newItem is ImplementedByAllExpression iba)
            {
                return(entityIDs.Select(kvp => Expression.And(
                                            EqualNullable(new PrimaryKeyExpression(QueryBinder.TypeConstant(kvp.Key).Nullify()), iba.TypeId.TypeColumn),
                                            InPrimaryKey(iba.Id, kvp.Value))).AggregateOr());
            }

            throw new InvalidOperationException("EntityIn not defined for newItem of type {0}".FormatWith(newItem.Type.Name));
        }
Пример #7
0
 public static Expression In(Expression element, object[] values)
 {
     return(InExpression.FromValues(DbExpressionNominator.FullNominate(element), values));
 }