public override Expression BindParameter(ParameterExpression parameter, Dictionary <Expression, Expression> processedExpressions)
        {
            Expression value;

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

            var result = new StructureFieldExpression(PersistentType, Field, Mapping, OuterParameter, DefaultIfEmpty);

            processedExpressions.Add(this, result);
            var processedFields = Fields
                                  .Select(f => f.BindParameter(parameter, processedExpressions))
                                  .Cast <PersistentFieldExpression>()
                                  .ToList();

            if (Owner == null)
            {
                result.fields = processedFields;
                return(result);
            }

            result.Fields = processedFields;
            Owner.BindParameter(parameter, processedExpressions);
            return(result);
        }
Example #2
0
        public override Expression Remap(int offset, Dictionary <Expression, Expression> processedExpressions)
        {
            if (!CanRemap)
            {
                return(this);
            }

            Expression value;

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

            var mapping = new Segment <int>(Mapping.Offset + offset, Mapping.Length);
            var result  = new StructureFieldExpression(PersistentType, Field, mapping, OuterParameter, DefaultIfEmpty);

            processedExpressions.Add(this, result);
            var processedFields = Fields
                                  .Select(f => f.Remap(offset, processedExpressions))
                                  .Cast <PersistentFieldExpression>()
                                  .ToList();

            if (Owner == null)
            {
                result.fields = processedFields;
                return(result);
            }

            result.Fields = processedFields;
            Owner.Remap(offset, processedExpressions);
            return(result);
        }
        public override FieldExpression RemoveOwner()
        {
            if (Owner == null)
            {
                return(this);
            }
            var result = new StructureFieldExpression(PersistentType, Field, Mapping, OuterParameter, DefaultIfEmpty);

            result.fields = fields
                            .Cast <FieldExpression>()
                            .Select(f => (PersistentFieldExpression)f.RemoveOwner())
                            .ToList();
            return(result);
        }
        public static StructureFieldExpression CreateStructure(FieldInfo structureField, int offset)
        {
            if (!structureField.IsStructure)
            {
                throw new ArgumentException(string.Format(Strings.ExFieldIsNotStructure, structureField.Name));
            }
            var persistentType = structureField.ReflectedType.Model.Types[structureField.ValueType];
            var mapping        = new Segment <int>(offset + structureField.MappingInfo.Offset, structureField.MappingInfo.Length);
            var result         = new StructureFieldExpression(persistentType, structureField, mapping, null, false);

            result.Fields = persistentType.Fields
                            .Select(f => BuildNestedFieldExpression(f, offset + structureField.MappingInfo.Offset))
                            .ToList();
            return(result);
        }
Example #5
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 Remap(int[] map, Dictionary <Expression, Expression> processedExpressions)
        {
            if (!CanRemap)
            {
                return(this);
            }

            Expression value;

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

            var result = new StructureFieldExpression(PersistentType, Field, default(Segment <int>), OuterParameter, DefaultIfEmpty);

            processedExpressions.Add(this, result);
            var processedFields = Fields
                                  .Select(f => f.Remap(map, processedExpressions))
                                  .Where(f => f != null)
                                  .Cast <PersistentFieldExpression>()
                                  .ToList();

            if (processedFields.Count == 0)
            {
                processedExpressions[this] = null;
                return(null);
            }
            var length = processedFields.Select(f => f.Mapping.Offset).Distinct().Count();
            var offset = processedFields.Min(f => f.Mapping.Offset);

            result.Mapping = new Segment <int>(offset, length);
            if (Owner == null)
            {
                result.fields = processedFields;
                return(result);
            }
            result.Fields = processedFields;
            Owner.Remap(map, processedExpressions);
            return(result);
        }