Exemplo n.º 1
0
 public static void AddNullabilityCondition(
     this MappingFragment entityTypeMapppingFragment,
     EdmProperty column,
     bool isNull)
 {
     entityTypeMapppingFragment.AddConditionProperty((ConditionPropertyMapping) new IsNullConditionMapping(column, isNull));
 }
Exemplo n.º 2
0
 public static void AddDiscriminatorCondition(
     this MappingFragment entityTypeMapppingFragment,
     EdmProperty discriminatorColumn,
     object value)
 {
     entityTypeMapppingFragment.AddConditionProperty((ConditionPropertyMapping) new ValueConditionMapping(discriminatorColumn, value));
 }
Exemplo n.º 3
0
        public static void AddNullabilityCondition(
            this MappingFragment entityTypeMapppingFragment,
            EdmProperty column,
            bool isNull)
        {
            DebugCheck.NotNull(entityTypeMapppingFragment);
            DebugCheck.NotNull(column);

            entityTypeMapppingFragment
            .AddConditionProperty(
                new IsNullConditionMapping(column, isNull));
        }
Exemplo n.º 4
0
        public static void AddDiscriminatorCondition(
            this MappingFragment entityTypeMapppingFragment,
            EdmProperty discriminatorColumn,
            object value)
        {
            DebugCheck.NotNull(entityTypeMapppingFragment);
            DebugCheck.NotNull(discriminatorColumn);
            DebugCheck.NotNull(value);

            entityTypeMapppingFragment
            .AddConditionProperty(
                new ValueConditionMapping(discriminatorColumn, value));
        }
Exemplo n.º 5
0
        // <summary>
        // Makes sure only the required property mappings are present
        // </summary>
        private static void ConfigureTypeMappings(
            TableMapping tableMapping,
            Dictionary <EntityType, EntityTypeMapping> rootMappings,
            EntityType entityType,
            MappingFragment propertiesTypeMappingFragment,
            MappingFragment conditionTypeMappingFragment)
        {
            var existingPropertyMappings =
                new List <ColumnMappingBuilder>(
                    propertiesTypeMappingFragment.ColumnMappings.Where(pm => !pm.ColumnProperty.IsPrimaryKeyColumn));
            var existingConditions = new List <ConditionPropertyMapping>(propertiesTypeMappingFragment.ColumnConditions);

            foreach (var columnMapping in from cm in tableMapping.ColumnMappings
                     from pm in cm.PropertyMappings
                     where pm.EntityType == entityType
                     select new
            {
                cm.Column,
                Property = pm
            })
            {
                if (columnMapping.Property.PropertyPath != null
                    &&
                    !IsRootTypeMapping(
                        rootMappings, columnMapping.Property.EntityType, columnMapping.Property.PropertyPath))
                {
                    var existingPropertyMapping =
                        propertiesTypeMappingFragment.ColumnMappings.SingleOrDefault(
                            x => x.PropertyPath == columnMapping.Property.PropertyPath);
                    if (existingPropertyMapping != null)
                    {
                        existingPropertyMappings.Remove(existingPropertyMapping);
                    }
                    else
                    {
                        existingPropertyMapping
                            = new ColumnMappingBuilder(columnMapping.Column, columnMapping.Property.PropertyPath);

                        propertiesTypeMappingFragment.AddColumnMapping(existingPropertyMapping);
                    }
                }

                if (columnMapping.Property.Conditions != null)
                {
                    foreach (var condition in columnMapping.Property.Conditions)
                    {
                        if (conditionTypeMappingFragment.ColumnConditions.Contains(condition))
                        {
                            existingConditions.Remove(condition);
                        }
                        else if (!entityType.Abstract)
                        {
                            conditionTypeMappingFragment.AddConditionProperty(condition);
                        }
                    }
                }
            }

            // Any leftover mappings are removed
            foreach (var leftoverPropertyMapping in existingPropertyMappings)
            {
                propertiesTypeMappingFragment.RemoveColumnMapping(leftoverPropertyMapping);
            }

            foreach (var leftoverCondition in existingConditions)
            {
                conditionTypeMappingFragment.RemoveConditionProperty(leftoverCondition);
            }

            if (entityType.Abstract)
            {
                propertiesTypeMappingFragment.ClearConditions();
            }
        }
Exemplo n.º 6
0
        private static void ConfigureTypeMappings(
            TableMapping tableMapping,
            Dictionary <EntityType, EntityTypeMapping> rootMappings,
            EntityType entityType,
            MappingFragment propertiesTypeMappingFragment,
            MappingFragment conditionTypeMappingFragment)
        {
            List <ColumnMappingBuilder>     columnMappingBuilderList     = new List <ColumnMappingBuilder>(propertiesTypeMappingFragment.ColumnMappings.Where <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => !pm.ColumnProperty.IsPrimaryKeyColumn)));
            List <ConditionPropertyMapping> conditionPropertyMappingList = new List <ConditionPropertyMapping>(propertiesTypeMappingFragment.ColumnConditions);

            foreach (var data in tableMapping.ColumnMappings.SelectMany((Func <ColumnMapping, IEnumerable <PropertyMappingSpecification> >)(cm => (IEnumerable <PropertyMappingSpecification>)cm.PropertyMappings), (cm, pm) => new
            {
                cm = cm,
                pm = pm
            }).Where(_param1 => _param1.pm.EntityType == entityType).Select(_param0 => new
            {
                Column = _param0.cm.Column,
                Property = _param0.pm
            }))
            {
                var columnMapping = data;
                if (columnMapping.Property.PropertyPath != null && !EntityMappingService.IsRootTypeMapping(rootMappings, columnMapping.Property.EntityType, columnMapping.Property.PropertyPath))
                {
                    ColumnMappingBuilder columnMappingBuilder1 = propertiesTypeMappingFragment.ColumnMappings.SingleOrDefault <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(x => x.PropertyPath == columnMapping.Property.PropertyPath));
                    if (columnMappingBuilder1 != null)
                    {
                        columnMappingBuilderList.Remove(columnMappingBuilder1);
                    }
                    else
                    {
                        ColumnMappingBuilder columnMappingBuilder2 = new ColumnMappingBuilder(columnMapping.Column, columnMapping.Property.PropertyPath);
                        propertiesTypeMappingFragment.AddColumnMapping(columnMappingBuilder2);
                    }
                }
                if (columnMapping.Property.Conditions != null)
                {
                    foreach (ConditionPropertyMapping condition in (IEnumerable <ConditionPropertyMapping>)columnMapping.Property.Conditions)
                    {
                        if (conditionTypeMappingFragment.ColumnConditions.Contains <ConditionPropertyMapping>(condition))
                        {
                            conditionPropertyMappingList.Remove(condition);
                        }
                        else if (!entityType.Abstract)
                        {
                            conditionTypeMappingFragment.AddConditionProperty(condition);
                        }
                    }
                }
            }
            foreach (ColumnMappingBuilder columnMappingBuilder in columnMappingBuilderList)
            {
                propertiesTypeMappingFragment.RemoveColumnMapping(columnMappingBuilder);
            }
            foreach (ConditionPropertyMapping condition in conditionPropertyMappingList)
            {
                conditionTypeMappingFragment.RemoveConditionProperty(condition);
            }
            if (!entityType.Abstract)
            {
                return;
            }
            propertiesTypeMappingFragment.ClearConditions();
        }