Ejemplo n.º 1
0
 private ImplementedByExpression CombineIB(ImplementedByExpression a, ImplementedByExpression b, Type type, Func <Expression, Expression, Expression> combiner)
 {
     return(new ImplementedByExpression(type, a.Strategy,
                                        a.Implementations.OuterJoinDictionaryCC(b.Implementations,
                                                                                (t, ia, ib) => CombineEntity(ia ?? NullEntity(t), ib ?? NullEntity(t), t, combiner)
                                                                                )));
 }
Ejemplo n.º 2
0
        static Expression EntityIn(Expression newItem, Dictionary <Type, PrimaryKey[]> entityIDs)
        {
            EntityExpression ee = newItem as EntityExpression;

            if (ee != null)
            {
                return(InPrimaryKey(ee.ExternalId, entityIDs.TryGetC(ee.Type) ?? new PrimaryKey[0]));
            }

            ImplementedByExpression ib = newItem as ImplementedByExpression;

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

            ImplementedByAllExpression iba = newItem as ImplementedByAllExpression;

            if (iba != null)
            {
                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));
        }
Ejemplo n.º 3
0
        static Expression IbIbaEquals(ImplementedByExpression ib, ImplementedByAllExpression iba)
        {
            var list = ib.Implementations.Values.Select(i =>
                                                        Expression.And(
                                                            i.ExternalId.Value == NewId ? (Expression)False : EqualNullable(iba.Id, new SqlCastExpression(typeof(string), i.ExternalId.Value)),
                                                            EqualNullable(iba.TypeId.TypeColumn.Value, QueryBinder.TypeConstant(i.Type)))).ToList();

            return(list.AggregateOr());
        }
Ejemplo n.º 4
0
        protected internal virtual Expression VisitImplementedBy(ImplementedByExpression ib)
        {
            var implementations = Visit(ib.Implementations, v => (EntityExpression)Visit(v));

            if (implementations != ib.Implementations)
            {
                return(new ImplementedByExpression(ib.Type, ib.Strategy, implementations));
            }
            return(ib);
        }
Ejemplo n.º 5
0
        static Expression FieIbEquals(EntityExpression ee, ImplementedByExpression ib)
        {
            var imp = ib.Implementations.TryGetC(ee.Type);

            if (imp == null)
            {
                return(False);
            }

            return(EqualNullable(imp.ExternalId.Value, ee.ExternalId.Value));
        }
Ejemplo n.º 6
0
        static Expression EntityIbEquals(EntityExpression ee, ImplementedByExpression ib)
        {
            var imp = ib.Implementations.TryGetC(ee.Type);

            if (imp == null)
            {
                return(False);
            }

            return(EntityEntityEquals(imp, ee));
        }
Ejemplo n.º 7
0
 protected override Expression VisitImplementedBy(ImplementedByExpression reference)
 {
     throw InvalidSqlExpression(reference);
 }
Ejemplo n.º 8
0
        static Expression IbIbEquals(ImplementedByExpression ib, ImplementedByExpression ib2)
        {
            var list = ib.Implementations.JoinDictionary(ib2.Implementations, (t, i, j) => EqualNullable(i.ExternalId.Value, j.ExternalId.Value)).Values.ToList();

            return(list.AggregateOr());
        }
Ejemplo n.º 9
0
 protected internal override Expression VisitImplementedBy(ImplementedByExpression reference)
 {
     throw InvalidSqlExpression(reference);
 }
Ejemplo n.º 10
0
 protected virtual bool CompareImplementedBy(ImplementedByExpression a, ImplementedByExpression b)
 {
     return(CompareDictionaries(a.Implementations, b.Implementations, Compare));
 }
Ejemplo n.º 11
0
        static Expression IbIbEquals(ImplementedByExpression ib, ImplementedByExpression ib2)
        {
            var list = ib.Implementations.JoinDictionary(ib2.Implementations, (t, i, j) => EntityEntityEquals(i, j)).Values.ToList();

            return(list.AggregateOr());
        }
Ejemplo n.º 12
0
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id)
        {
            var implementations = ImplementationColumns.SelectDictionary(t => t, (t, ic) =>
                 new EntityExpression(t, new PrimaryKeyExpression(new ColumnExpression(ic.Type.Nullify(), tableAlias, ic.Name)), 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.º 13
0
        static Expression IbIbaEquals(ImplementedByExpression ib, ImplementedByAllExpression iba)
        {
            var list = ib.Implementations.Values.Select(i => Expression.And(
                EqualNullable(iba.Id, i.ExternalId),
                EqualNullable(iba.TypeId.TypeColumn, QueryBinder.TypeConstant(i.Type)))).ToList();

            return list.AggregateOr();
        }
Ejemplo n.º 14
0
 protected internal override Expression VisitImplementedBy(ImplementedByExpression rb)
 {
     return(rb.Implementations.Select(ee => new When(Visit(ee.Value.ExternalId).NotEqualsNulll(), Visit(ee.Value))).ToCondition(rb.Type));
 }
Ejemplo n.º 15
0
        protected virtual Expression VisitImplementedBy(ImplementedByExpression ib)
        {
            var implementations = ib.Implementations.NewIfChange(v => (EntityExpression)Visit(v));

            if (implementations != ib.Implementations)
                return new ImplementedByExpression(ib.Type, ib.Strategy, implementations);
            return ib;
        }
Ejemplo n.º 16
0
        static Expression IbIbaEquals(ImplementedByExpression ib, ImplementedByAllExpression iba)
        {
            var list = ib.Implementations.Values.Select(i =>
                Expression.And(
                i.ExternalId.Value == NewId ? (Expression)False : EqualNullable(iba.Id, new SqlCastExpression(typeof(string), i.ExternalId.Value)),
                EqualNullable(iba.TypeId.TypeColumn.Value, QueryBinder.TypeConstant(i.Type)))).ToList();

            return list.AggregateOr();
        }
Ejemplo n.º 17
0
        static Expression IbIbEquals(ImplementedByExpression ib, ImplementedByExpression ib2)
        {
            var list = ib.Implementations.JoinDictionary(ib2.Implementations, (t, i, j) => EqualNullable(i.ExternalId.Value, j.ExternalId.Value)).Values.ToList();

            return list.AggregateOr();
        }
Ejemplo n.º 18
0
        static Expression FieIbEquals(EntityExpression ee, ImplementedByExpression ib)
        {
            var imp = ib.Implementations.TryGetC(ee.Type);
            if (imp == null)
                return False;

            return EqualNullable(imp.ExternalId.Value, ee.ExternalId.Value); 
        }