public override Expression Remap(int offset, Dictionary <Expression, Expression> processedExpressions)
        {
            if (!CanRemap)
            {
                return(this);
            }

            Expression result;

            if (processedExpressions.TryGetValue(this, out result))
            {
                return(result);
            }

            var mapping = new Segment <int>(Mapping.Offset + offset, Mapping.Length);

            result = new FieldExpression(ExtendedExpressionType.Field, Field, mapping, OuterParameter, DefaultIfEmpty);
            if (owner == null)
            {
                return(result);
            }

            processedExpressions.Add(this, result);
            Owner.Remap(offset, processedExpressions);
            return(result);
        }
        public static EntityExpression Create(TypeInfo typeInfo, int offset, bool keyFieldsOnly)
        {
            if (!typeInfo.IsEntity && !typeInfo.IsInterface)
            {
                throw new ArgumentException(string.Format(Strings.ExPersistentTypeXIsNotEntityOrPersistentInterface, typeInfo.Name), "typeInfo");
            }
            var fields        = new List <PersistentFieldExpression>();
            var keyExpression = KeyExpression.Create(typeInfo, offset);

            fields.Add(keyExpression);
            var result = new EntityExpression(typeInfo, keyExpression, null, false);

            if (keyFieldsOnly)
            {
                // Add key fields to field collection
                var keyFieldClones = keyExpression
                                     .KeyFields
                                     .Select(kf => FieldExpression.CreateField(kf.Field, offset))
                                     .Cast <PersistentFieldExpression>();
                fields.AddRange(keyFieldClones);
            }
            else
            {
                foreach (var nestedField in typeInfo.Fields)
                {
                    fields.Add(BuildNestedFieldExpression(nestedField, offset));
                }
            }
            result.Fields = fields;
            return(result);
        }
예제 #3
0
        public static KeyExpression Create(TypeInfo entityType, int offset)
        {
            var mapping = new Segment <int>(offset, entityType.Key.TupleDescriptor.Count);
            var fields  = entityType.Columns
                          .Where(c => c.IsPrimaryKey)
                          .OrderBy(c => c.Field.MappingInfo.Offset)
                          .Select(c => FieldExpression.CreateField(c.Field, offset))
                          .ToList()
                          .AsReadOnly();

            return(new KeyExpression(entityType, fields, mapping, WellKnownMembers.IEntityKey, null, false));
        }
예제 #4
0
// ReSharper disable RedundantNameQualifier
        private static PersistentFieldExpression BuildNestedFieldExpression(FieldInfo nestedField, int offset)
        {
            if (nestedField.IsPrimitive)
            {
                return(FieldExpression.CreateField(nestedField, offset));
            }
            if (nestedField.IsStructure)
            {
                return(StructureFieldExpression.CreateStructure(nestedField, offset));
            }
            if (nestedField.IsEntity)
            {
                return(EntityFieldExpression.CreateEntityField(nestedField, offset));
            }
            throw new NotSupportedException(string.Format(Strings.ExNestedFieldXIsNotSupported, nestedField.Attributes));
        }
        public override Expression RemoveOuterParameter(Dictionary <Expression, Expression> processedExpressions)
        {
            Expression result;

            if (processedExpressions.TryGetValue(this, out result))
            {
                return(result);
            }

            result = new FieldExpression(ExtendedExpressionType.Field, Field, Mapping, null, DefaultIfEmpty);
            if (owner == null)
            {
                return(result);
            }

            processedExpressions.Add(this, result);
            Owner.RemoveOuterParameter(processedExpressions);
            return(result);
        }
        public override Expression Remap(int[] map, Dictionary <Expression, Expression> processedExpressions)
        {
            if (!CanRemap)
            {
                return(this);
            }

            Expression result;

            if (processedExpressions.TryGetValue(this, out result))
            {
                return(result);
            }

            var offset = map.IndexOf(Mapping.Offset);

            if (offset < 0)
            {
                if (owner == null && !SkipOwnerCheckScope.IsActive)
                {
                    throw new InvalidOperationException(Strings.ExUnableToRemapFieldExpression);
                }
                processedExpressions.Add(this, null);
                if (owner != null)
                {
                    Owner.Remap(map, processedExpressions);
                }
                return(null);
            }
            var mapping = new Segment <int>(offset, Mapping.Length);

            result = new FieldExpression(ExtendedExpressionType.Field, Field, mapping, OuterParameter, DefaultIfEmpty);
            if (owner == null)
            {
                return(result);
            }

            processedExpressions.Add(this, result);
            Owner.Remap(map, processedExpressions);
            return(result);
        }
예제 #7
0
        public override Expression Remap(int[] map, Dictionary <Expression, Expression> processedExpressions)
        {
            if (!CanRemap)
            {
                return(this);
            }

            if (processedExpressions.TryGetValue(this, out var value))
            {
                return(value);
            }

            var segment = new Segment <int>(map.IndexOf(Mapping.Offset), Mapping.Length);
            var fields  = new FieldExpression[KeyFields.Count];

            using (new SkipOwnerCheckScope()) {
                for (var index = 0; index < fields.Length; index++)
                {
                    var field = (FieldExpression)KeyFields[index].Remap(map, processedExpressions);
                    if (field == null)
                    {
                        if (SkipOwnerCheckScope.IsActive)
                        {
                            processedExpressions.Add(this, null);
                            return(null);
                        }
                        throw Exceptions.InternalError(Strings.ExUnableToRemapKeyExpression, OrmLog.Instance);
                    }

                    fields[index] = field;
                }
            }
            var result = new KeyExpression(EntityType, fields, segment, UnderlyingProperty, OuterParameter, DefaultIfEmpty);

            processedExpressions.Add(this, result);
            return(result);
        }