private bool FieldsEquals(PropertyRoute other)
        {
            if (FieldInfo == null)
            {
                return(other.FieldInfo == null);
            }

            return(other.FieldInfo != null && ReflectionTools.FieldEquals(FieldInfo, other.FieldInfo));
        }
        public Expression GetBinding(FieldInfo fi)
        {
            if (Bindings == null)
            {
                throw new InvalidOperationException("EntityInitiExpression not completed");
            }

            FieldBinding binding = Bindings.Where(fb => ReflectionTools.FieldEquals(fi, fb.FieldInfo)).SingleEx(() => "field '{0}' in {1} (field Ignored?)".FormatWith(fi.Name, this.Type.TypeName()));

            return(binding.Binding);
        }
示例#3
0
        internal ReadOnlyCollection <FieldBinding> GenerateBindings(Alias tableAlias, QueryBinder binder, Expression id)
        {
            List <FieldBinding> result = new List <FieldBinding>();

            result.Add(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)));
                }
            }


            return(result.ToReadOnly());
        }
示例#4
0
        protected virtual KindOfField?GetKindOfField(PropertyRoute route)
        {
            if (route.FieldInfo != null && ReflectionTools.FieldEquals(route.FieldInfo, fiId))
            {
                return(KindOfField.PrimaryKey);
            }

            if (route.FieldInfo != null && ReflectionTools.FieldEquals(route.FieldInfo, fiTicks))
            {
                return(KindOfField.Ticks);
            }

            if (Settings.GetSqlDbType(Settings.FieldAttribute <SqlDbTypeAttribute>(route), route.Type) != null)
            {
                return(KindOfField.Value);
            }

            if (route.Type.UnNullify().IsEnum)
            {
                return(KindOfField.Enum);
            }

            if (Reflector.IsIEntity(Lite.Extract(route.Type) ?? route.Type))
            {
                return(KindOfField.Reference);
            }

            if (Reflector.IsEmbeddedEntity(route.Type))
            {
                return(KindOfField.Embedded);
            }

            if (Reflector.IsMList(route.Type))
            {
                return(KindOfField.MList);
            }

            return(null);
        }
示例#5
0
        internal ReadOnlyCollection <FieldBinding> GenerateBindings(Alias tableAlias, QueryBinder binder, Expression id)
        {
            List <FieldBinding> result = new List <FieldBinding>();

            result.Add(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)));
                }
            }

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

            return(result.ToReadOnly());
        }
            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));
            }
示例#7
0
        internal ReadOnlyCollection <FieldBinding> GenerateBindings(Alias tableAlias, QueryBinder binder, Expression id, IntervalExpression?period, EntityContextInfo?entityContext)
        {
            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, entityContext)));
                }
            }

            if (this.Type.IsEntity() && entityContext != null)
            {
                result.AddRange(Schema.Current.GetAdditionalQueryBindings(PropertyRoute.Root(this.Type), entityContext, period));
            }

            return(result.ToReadOnly());
        }
 public static bool FieldEquals <S, T>(this FieldInfo fi, Expression <Func <S, T> > field)
 {
     return(ReflectionTools.FieldEquals(ReflectionTools.BaseFieldInfo(field), fi));
 }
 public Expression GetBinding(FieldInfo fi)
 {
     return(Bindings.SingleEx(fb => ReflectionTools.FieldEquals(fi, fb.FieldInfo)).Binding);
 }
示例#10
0
 protected virtual bool CompareFieldBinding(FieldBinding a, FieldBinding b)
 {
     return(ReflectionTools.FieldEquals(a.FieldInfo, b.FieldInfo) && Compare(a.Binding, b.Binding));
 }
示例#11
0
        public Expression GetViewId()
        {
            var field = ViewTable.GetViewPrimaryKey();

            return(this.Bindings.SingleEx(b => ReflectionTools.FieldEquals(b.FieldInfo, field.FieldInfo)).Binding);
        }