protected internal override Expression VisitEntity(EntityExpression fieldInit)
            {
                Expression id = Visit(NullifyColumn(fieldInit.ExternalId));

                if (fieldInit.TableAlias == null)
                {
                    return(Expression.Call(retriever, miRequest.MakeGenericMethod(fieldInit.Type), id));
                }

                ParameterExpression e = Expression.Parameter(fieldInit.Type, fieldInit.Type.Name.ToLower().Substring(0, 1));

                var bindings =
                    fieldInit.Bindings
                    .Where(a => !ReflectionTools.FieldEquals(EntityExpression.IdField, a.FieldInfo))
                    .Select(b =>
                {
                    var field = Expression.Field(e, b.FieldInfo);

                    var value = b.Binding is ChildProjectionExpression ?
                                VisitMListChildProjection((ChildProjectionExpression)b.Binding, field) :
                                Convert(Visit(b.Binding), b.FieldInfo.FieldType);

                    return((Expression)Expression.Assign(field, value));
                }).ToList();

                if (fieldInit.Mixins != null)
                {
                    var blocks = fieldInit.Mixins.Select(m => AssignMixin(e, m)).ToList();

                    bindings.AddRange(blocks);
                }

                LambdaExpression lambda = Expression.Lambda(typeof(Action <>).MakeGenericType(fieldInit.Type), Expression.Block(bindings), e);

                return(Expression.Call(retriever, miCached.MakeGenericMethod(fieldInit.Type), id.Nullify(), lambda));
            }
Esempio n. 2
0
        protected internal override Expression VisitEntity(EntityExpression ee)
        {
            if (previousTypes.Contains(ee.Type) || IsCached(ee.Type) || ee.AvoidExpandOnRetrieving)
            {
                ee = new EntityExpression(ee.Type, ee.ExternalId, null, null, null, ee.AvoidExpandOnRetrieving);
            }
            else
            {
                ee = binder.Completed(ee);
            }

            previousTypes = previousTypes.Push(ee.Type);

            var bindings = Visit(ee.Bindings, VisitFieldBinding);
            var mixins   = Visit(ee.Mixins, VisitMixinEntity);

            var id = (PrimaryKeyExpression)Visit(ee.ExternalId);

            var result = new EntityExpression(ee.Type, id, ee.TableAlias, bindings, mixins, ee.AvoidExpandOnRetrieving);

            previousTypes = previousTypes.Pop();

            return(result);
        }
        internal Expression GetProjectorExpression(Alias tableAlias, QueryBinder binder)
        {
            Expression id = GetIdExpression(tableAlias);

            if (IsView)
            {
                var bindings = this.Fields.Values.Select(ef=>new FieldBinding(ef.FieldInfo, ef.Field.GetExpression(tableAlias, binder, id))).ToReadOnly();

                var hasValue = id == null ? Expression.Constant(true): SmartEqualizer.NotEqualNullable(id, Expression.Constant(null, id.Type.Nullify()));

                return new EmbeddedEntityExpression(this.Type, hasValue, bindings, null);
            }
            else
            {
                var bindings = GenerateBindings(tableAlias, binder, id); 
                var mixins = GenerateMixins(tableAlias, binder, id);

                Schema.Current.AssertAllowed(Type, inUserInterface: false);

                var result = new EntityExpression(this.Type, (PrimaryKeyExpression)id, tableAlias, bindings, mixins, avoidExpandOnRetrieving: false);

                return result; 
            }
        }
Esempio n. 4
0
 public MListElementExpression(Expression rowId, EntityExpression parent, Expression element, TableMList table)
     : base(DbExpressionType.MListElement, typeof(MListElement<,>).MakeGenericType(parent.Type, element.Type))
 {
     this.RowId = rowId;
     this.Parent = parent;
     this.Element = element;
     this.Table = table;
 }
Esempio n. 5
0
        protected internal override Expression VisitEntity(EntityExpression entity)
        {
            var newID = (PrimaryKeyExpression)Visit(entity.ExternalId);

            return(new EntityExpression(entity.Type, newID, null, null, null, null, null, entity.AvoidExpandOnRetrieving)); // remove bindings
        }
Esempio n. 6
0
        protected override Expression VisitEntity(EntityExpression fieldInit)
        {
            Expression newID = Visit(fieldInit.ExternalId);

            return new EntityExpression(fieldInit.Type, newID, null, null, null, fieldInit.AvoidExpandOnRetrieving); // remove bindings
        }
Esempio n. 7
0
 private EntityExpression CombineEntity(EntityExpression a, EntityExpression b, Type type, Func <Expression, Expression, Expression> combiner)
 {
     return(new EntityExpression(type, new PrimaryKeyExpression(combiner(a.ExternalId.Value, b.ExternalId.Value)), null, null, null, null, null, a.AvoidExpandOnRetrieving || b.AvoidExpandOnRetrieving));
 }
Esempio n. 8
0
        protected override Expression VisitEntity(EntityExpression ee)
        {
            if (previousTypes.Contains(ee.Type) || IsCached(ee.Type) || ee.AvoidExpandOnRetrieving)
            {
                ee = new EntityExpression(ee.Type, ee.ExternalId, null, null, null, ee.AvoidExpandOnRetrieving);
            }
            else
                ee = binder.Completed(ee);

            previousTypes = previousTypes.Push(ee.Type);

            var bindings = ee.Bindings.NewIfChange(VisitFieldBinding);
            var mixins = ee.Mixins.NewIfChange(VisitMixinEntity);

            var id = Visit(ee.ExternalId);

            var result = new EntityExpression(ee.Type, id, ee.TableAlias, bindings, mixins, ee.AvoidExpandOnRetrieving);

            previousTypes = previousTypes.Pop();

            return result;
        }
Esempio n. 9
0
 protected internal override Expression VisitEntity(EntityExpression ee)
 {
     throw InvalidSqlExpression(ee);
 }
Esempio n. 10
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); 
        }
Esempio n. 11
0
 static Expression FieFieEquals(EntityExpression fie1, EntityExpression fie2)
 {
     if (fie1.Type == fie2.Type)
         return PolymorphicEqual(fie1.ExternalId, fie2.ExternalId);
     else
         return False;
 }
Esempio n. 12
0
        protected virtual Expression VisitEntity(EntityExpression ee)
        {
            var bindings = ee.Bindings.NewIfChange(VisitFieldBinding);
            var mixins = ee.Mixins.NewIfChange(VisitMixinEntity);

            var id = Visit(ee.ExternalId);

            if (ee.Bindings != bindings || ee.ExternalId != id || ee.Mixins != mixins)
                return new EntityExpression(ee.Type, id, ee.TableAlias, bindings, mixins, ee.AvoidExpandOnRetrieving);

            return ee;
        }
Esempio n. 13
0
        public static Expression ConstantToLite(Expression expression)
        {
            ConstantExpression c = expression as ConstantExpression;
            if (c == null)
                return null;

            if (c.Value == null)
                return c;

            if (c.Type.IsLite())
            {
                Lite<IIdentifiable> lite = (Lite<IIdentifiable>)c.Value;

                Expression id = Expression.Constant(lite.IdOrNull ?? int.MinValue);

                EntityExpression ere = new EntityExpression(lite.EntityType, id, null, null, null, false);

                return new LiteReferenceExpression(Lite.Generate(lite.EntityType), ere, null);
            }

            return null;
        }
Esempio n. 14
0
 static Expression FieIbaEquals(EntityExpression ee, ImplementedByAllExpression iba)
 {
     return Expression.And(EqualNullable(ee.ExternalId, iba.Id), EqualNullable(QueryBinder.TypeConstant(ee.Type), iba.TypeId.TypeColumn));
 }
Esempio n. 15
0
 static Expression FieFieEquals(EntityExpression fie1, EntityExpression fie2)
 {
     if (fie1.Type == fie2.Type)
         return EqualNullable(fie1.ExternalId, fie2.ExternalId);
     else
         return False;
 }
        internal override Expression GetExpression(Alias tableAlias, QueryBinder binder, Expression id)
        {
            Type cleanType = IsLite ? Lite.Extract(FieldType) : FieldType;

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

            if(this.IsLite)
                return binder.MakeLite(result, null);
            else 
                return result; 
        }
Esempio n. 17
0
 static Expression FieIbaEquals(EntityExpression ee, ImplementedByAllExpression iba)
 {
     return Expression.And(
         ee.ExternalId.Value == NewId ? False : EqualNullable(new SqlCastExpression(typeof(string), ee.ExternalId.Value), iba.Id),
         EqualNullable(QueryBinder.TypeConstant(ee.Type), iba.TypeId.TypeColumn.Value));
 }
Esempio n. 18
0
        public static Expression ConstantToLite(Expression expression)
        {
            ConstantExpression c = expression as ConstantExpression;
            if (c == null)
                return null;

            if (c.Value == null)
                return c;

            if (c.Type.IsLite())
            {
                Lite<IEntity> lite = (Lite<IEntity>)c.Value;

                var id = lite.IdOrNull?.Let(pk => Expression.Constant(pk.Object, PrimaryKey.Type(lite.EntityType).Nullify())) ?? SmartEqualizer.NewId;

                EntityExpression ere = new EntityExpression(lite.EntityType, new PrimaryKeyExpression(id), null, null, null, false);

                return new LiteReferenceExpression(Lite.Generate(lite.EntityType), ere, null);
            }

            return null;
        }
Esempio n. 19
0
 static Expression FieIbaEquals(EntityExpression ee, ImplementedByAllExpression iba)
 {
     return(Expression.And(
                ee.ExternalId.Value == NewId ? False : EqualNullable(new SqlCastExpression(typeof(string), ee.ExternalId.Value), iba.Id),
                EqualNullable(QueryBinder.TypeConstant(ee.Type), iba.TypeId.TypeColumn.Value)));
 }
Esempio n. 20
0
 protected override Expression VisitEntity(EntityExpression ee)
 {
     throw InvalidSqlExpression(ee);
 }