Ejemplo n.º 1
0
 public AdditionalFieldExpression(Type type, PrimaryKeyExpression backID, NewExpression?externalPeriod, PropertyRoute route)
     : base(DbExpressionType.AdditionalField, type)
 {
     this.BackID         = backID;
     this.Route          = route;
     this.ExternalPeriod = externalPeriod;
 }
Ejemplo n.º 2
0
 public MListExpression(Type type, PrimaryKeyExpression backID, NewExpression?externalPeriod, TableMList tr)
     : base(DbExpressionType.MList, type)
 {
     this.BackID         = backID;
     this.ExternalPeriod = externalPeriod;
     this.TableMList     = tr;
 }
Ejemplo n.º 3
0
        public EntityExpression(Type type, PrimaryKeyExpression externalId,
                                NewExpression?externalPeriod,
                                Alias?tableAlias,
                                IEnumerable <FieldBinding>?bindings,
                                IEnumerable <MixinEntityExpression>?mixins,
                                NewExpression?tablePeriod, bool avoidExpandOnRetrieving)
            : base(DbExpressionType.Entity, type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (!type.IsEntity())
            {
                throw new ArgumentException("type");
            }
            this.Table      = Schema.Current.Table(type);
            this.ExternalId = externalId ?? throw new ArgumentNullException(nameof(externalId));

            this.TableAlias = tableAlias;
            this.Bindings   = bindings.ToReadOnly();
            this.Mixins     = mixins.ToReadOnly();

            this.ExternalPeriod = externalPeriod;
            this.TablePeriod    = tablePeriod;

            this.AvoidExpandOnRetrieving = avoidExpandOnRetrieving;
        }
Ejemplo n.º 4
0
        private static IndexSaveRequest _createMessage(Action <IndexInfo <TSource> > index)
        {
            if (index == null)
            {
                throw new ArgumentNullException(nameof(index));
            }

            var info = new IndexInfo <TSource>();

            index.Invoke(info);

            Check.NotNull(info, nameof(info));
            Check.NotNull(info.IndexName !, "index must be not null or empty");
            Check.NotNull(info.Fields !, "fields must be not null or empty");


            NewExpression?body    = info?.Fields?.Body as NewExpression;
            var           fields  = body?.Arguments.Select(x => (x as MemberExpression)?.Member.Name);
            var           message = new IndexSaveRequest
            {
                Name = info?.IndexName, Index = new IndexSaveRequestFields {
                    Fields = fields
                }, Type = "json"
            };

            return(message);
        }
    protected override Expression VisitNew(NewExpression nex)
    {
        NewExpression?candidate = MakeCandidateMatch(nex);

        CheckEqual(nex.Constructor, candidate !.Constructor);
        CompareList(nex.Members, candidate.Members);
        return(base.VisitNew(nex));
    }
Ejemplo n.º 6
0
 public MListElementExpression(PrimaryKeyExpression rowId, EntityExpression parent, Expression?order, Expression element, NewExpression?systemPeriod, TableMList table, Alias alias)
     : base(DbExpressionType.MListElement, typeof(MListElement <,>).MakeGenericType(parent.Type, element.Type))
 {
     this.RowId       = rowId;
     this.Parent      = parent;
     this.Order       = order;
     this.Element     = element;
     this.TablePeriod = systemPeriod;
     this.Table       = table;
     this.Alias       = alias;
 }
        public static NewExpression CreateTupleExpression(IReadOnlyList <Expression> expressions)
        {
            if (expressions.Count < 8 || (expressions.Count == 8 && IsTupleType(expressions[7].Type)))
            {
                Type[] typeArguments = new Type[expressions.Count];
                for (int i = 0; i < typeArguments.Length; i++)
                {
                    Type type = expressions[i].Type;
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IOrderedEnumerable <>))
                    {
                        typeArguments[i] = typeof(IEnumerable <>).MakeGenericType(type.GetGenericArguments());
                    }
                    else
                    {
                        typeArguments[i] = type;
                    }
                }
                Type            tupleType = GetTupleType(typeArguments);
                ConstructorInfo ctorInfo  = tupleType.GetConstructor(typeArguments);
                return(Expression.New(ctorInfo, expressions, tupleType.GetProperties()));
            }

            NewExpression?restNew = null;
            int           count   = expressions.Count;

            while (count > 0)
            {
                int len = count % 7;
                if (len == 0)
                {
                    len = 7;
                }

                Expression[] restExpressions;
                if (restNew == null)
                {
                    restExpressions = new Expression[len];
                }
                else
                {
                    restExpressions      = new Expression[len + 1];
                    restExpressions[len] = restNew;
                }
                for (; len > 0; len--, count--)
                {
                    restExpressions[len - 1] = expressions[count - 1];
                }
                restNew = CreateTupleExpression(restExpressions);
            }
            return(restNew !);
        }
        /// <summary>Determines whether the specified <see cref="NewExpression"/>s are equal.</summary>
        /// <param name="x">The first <see cref="NewExpression"/> to compare.</param>
        /// <param name="y">The second <see cref="NewExpression"/> to compare.</param>
        /// <returns>true if the specified <see cref="NewExpression"/>s are equal; otherwise, false.</returns>
        bool IEqualityComparer <NewExpression> .Equals([AllowNull] NewExpression?x, [AllowNull] NewExpression?y)
        {
            if (ReferenceEquals(x, y))
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            return(EqualsNew(x, y, BeginScope()));
        }
Ejemplo n.º 9
0
        public ImplementedByAllExpression(Type type, Expression id, TypeImplementedByAllExpression typeId, NewExpression?externalPeriod)
            : base(DbExpressionType.ImplementedByAll, type)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (id.Type != typeof(string))
            {
                throw new ArgumentException("string");
            }
            this.Id             = id;
            this.TypeId         = typeId ?? throw new ArgumentNullException(nameof(typeId));
            this.ExternalPeriod = externalPeriod;
        }
Ejemplo n.º 10
0
        internal Expression GetProjectorExpression(Alias tableAlias, QueryBinder binder)
        {
            Schema.Current.AssertAllowed(this.BackReference.ReferenceTable.Type, inUserInterface: false);

            Type elementType = typeof(MListElement <,>).MakeGenericType(BackReference.FieldType, Field.FieldType);

            var           rowId  = RowIdExpression(tableAlias);
            NewExpression?period = GenerateSystemPeriod(tableAlias, binder);

            return(new MListElementExpression(
                       rowId,
                       (EntityExpression)this.BackReference.GetExpression(tableAlias, binder, null !, period),
                       this.Order == null ? null : OrderExpression(tableAlias),
                       this.Field.GetExpression(tableAlias, binder, rowId, period),
                       period,
                       this,
                       tableAlias));
        }
Ejemplo n.º 11
0
        internal Expression FieldExpression(Alias tableAlias, QueryBinder binder, NewExpression?externalPeriod, bool withRowId)
        {
            var rowId = RowIdExpression(tableAlias);

            var exp = Field.GetExpression(tableAlias, binder, rowId, externalPeriod);

            if (!withRowId)
            {
                return(exp);
            }

            var type = this.Field.FieldType;

            var ci = typeof(MList <> .RowIdElement).MakeGenericType(type).GetConstructor(new[] { type, typeof(PrimaryKey), typeof(int?) });

            var order = Order == null ? (Expression)Expression.Constant(null, typeof(int?)) : OrderExpression(tableAlias).Nullify();

            return(Expression.New(ci, exp, rowId.UnNullify(), order));
        }
Ejemplo n.º 12
0
        internal static Expression?Intesection(this NewExpression?interval1, NewExpression?interval2)
        {
            if (interval1 == null)
            {
                return(interval2);
            }

            if (interval2 == null)
            {
                return(interval1);
            }

            var min1 = interval1.Arguments[0];
            var max1 = interval1.Arguments[1];
            var min2 = interval2.Arguments[0];
            var max2 = interval2.Arguments[1];

            return(Expression.New(ciInterval,
                                  Expression.Condition(Expression.LessThan(min1, min2), min1, min2),
                                  Expression.Condition(Expression.GreaterThan(max1, max2), max1, max2)));
        }
Ejemplo n.º 13
0
        internal static Expression?Overlaps(this NewExpression?interval1, NewExpression?interval2)
        {
            if (interval1 == null)
            {
                return(null);
            }

            if (interval2 == null)
            {
                return(null);
            }

            var min1 = interval1.Arguments[0];
            var max1 = interval1.Arguments[1];
            var min2 = interval2.Arguments[0];
            var max2 = interval2.Arguments[1];

            return(Expression.And(
                       Expression.GreaterThan(max1, min2),
                       Expression.GreaterThan(max2, min1)
                       ));
        }
Ejemplo n.º 14
0
 internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
 {
     return(new PrimaryKeyExpression(new ColumnExpression(this.Type.Nullify(), tableAlias, this.Name).Nullify()));
 }
Ejemplo n.º 15
0
        internal ReadOnlyCollection <FieldBinding> GenerateBindings(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            List <FieldBinding> result = new List <FieldBinding>
            {
                new FieldBinding(Table.fiId, id)
            };

            foreach (var ef in this.Fields.Values)
            {
                var fi = ef.FieldInfo;

                if (!ReflectionTools.FieldEquals(fi, fiId))
                {
                    result.Add(new FieldBinding(fi, ef.Field.GetExpression(tableAlias, binder, id, period)));
                }
            }

            if (this.Type.IsEntity())
            {
                result.AddRange(Schema.Current.GetAdditionalQueryBindings(PropertyRoute.Root(this.Type), (PrimaryKeyExpression)id, period));
            }

            return(result.ToReadOnly());
        }
Ejemplo n.º 16
0
        internal ReadOnlyCollection <MixinEntityExpression>?GenerateMixins(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            if (this.Mixins == null)
            {
                return(null);
            }

            return(this.Mixins.Values.Select(m => (MixinEntityExpression)m.GetExpression(tableAlias, binder, id, period)).ToReadOnly());
        }
Ejemplo n.º 17
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            var implementations = ImplementationColumns.SelectDictionary(t => t, (t, ic) =>
                                                                         new EntityExpression(t, new PrimaryKeyExpression(new ColumnExpression(ic.Type.Nullify(), tableAlias, ic.Name)), period, null, null, null, null, AvoidExpandOnRetrieving));

            var result = new ImplementedByExpression(IsLite ? Lite.Extract(FieldType) ! : FieldType, SplitStrategy, implementations);

            if (this.IsLite)
            {
                return(binder.MakeLite(result, null));
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 18
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            Expression result = new ImplementedByAllExpression(
                IsLite ? Lite.Extract(FieldType) ! : FieldType,
                new ColumnExpression(Column.Type, tableAlias, Column.Name),
                new TypeImplementedByAllExpression(new PrimaryKeyExpression(new ColumnExpression(ColumnType.Type.Nullify(), tableAlias, ColumnType.Name))),
                period);

            if (this.IsLite)
            {
                return(binder.MakeLite(result, null));
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 19
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            var bindings = (from kvp in EmbeddedFields
                            let fi = kvp.Value.FieldInfo
                                     select new FieldBinding(fi, kvp.Value.Field.GetExpression(tableAlias, binder, id, period)))
                           .Concat(Schema.Current.GetAdditionalQueryBindings(this.Route, (PrimaryKeyExpression)id, period))
                           .ToReadOnly();

            Expression hasValue = HasValue == null?SmartEqualizer.NotEqualNullable(id,
                                                                                   id is PrimaryKeyExpression?QueryBinder.NullId(((PrimaryKeyExpression)id).ValueType) : (Expression)Expression.Constant(null, id.Type.Nullify())) :
                                      new ColumnExpression(((IColumn)HasValue).Type, tableAlias, HasValue.Name);

            return(new EmbeddedEntityExpression(this.FieldType, hasValue, bindings, this, null));
        }
Ejemplo n.º 20
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            var bindings = (from kvp in Fields
                            let fi = kvp.Value.FieldInfo
                                     select new FieldBinding(fi, kvp.Value.Field.GetExpression(tableAlias, binder, id, period)))
                           .Concat(Schema.Current.GetAdditionalQueryBindings(this.Route, (PrimaryKeyExpression)id, period))
                           .ToReadOnly();

            return(new MixinEntityExpression(this.FieldType, bindings, tableAlias, this));
        }
Ejemplo n.º 21
0
 internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
 {
     return(Expression.Convert(new ColumnExpression(this.Type, tableAlias, Name), FieldType));
 }
Ejemplo n.º 22
0
 internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
 {
     return(new MListExpression(FieldType, (PrimaryKeyExpression)id, period, TableMList)); // keep back id empty for some seconds
 }
Ejemplo n.º 23
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            Type cleanType = IsLite ? Lite.Extract(FieldType) ! : FieldType;

            var result = new EntityExpression(cleanType, new PrimaryKeyExpression(new ColumnExpression(this.Type.Nullify(), tableAlias, Name)), period, null, null, null, null, AvoidExpandOnRetrieving);

            if (this.IsLite)
            {
                return(binder.MakeLite(result, null));
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 24
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            if (this.Type == this.FieldType)
            {
                return(new ColumnExpression(this.Type, tableAlias, this.Name));
            }

            if (this.Type == typeof(DateTime))
            {
                return(Expression.Property(new ColumnExpression(this.Type, tableAlias, this.Name), piDateTimeTicks));
            }

            throw new NotImplementedException("FieldTicks of type {0} not supported".FormatWith(this.Type));
        }
Ejemplo n.º 25
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period)
        {
            var column = new ColumnExpression(this.Type, tableAlias, this.Name);

            if (this.Type == this.FieldType)
            {
                return(column);
            }

            return(Expression.Convert(column, this.FieldType));
        }
Ejemplo n.º 26
0
        internal IEnumerable <FieldBinding> GetAdditionalQueryBindings(PropertyRoute parent, PrimaryKeyExpression id, NewExpression?period)
        {
            //AssertAllowed(parent.RootType, inUserInterface: false);

            var ee = entityEvents.TryGetC(parent.RootType);

            if (ee == null || ee.AdditionalBindings == null)
            {
                return(Enumerable.Empty <FieldBinding>());
            }

            return(ee.AdditionalBindings
                   .Where(kvp => kvp.Key.Parent !.Equals(parent))
                   .Select(kvp => new FieldBinding(kvp.Key.FieldInfo !, new AdditionalFieldExpression(kvp.Key.FieldInfo !.FieldType, id, period, kvp.Key)))
                   .ToList());
        }
Ejemplo n.º 27
0
 internal abstract Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id, NewExpression?period);