Exemplo n.º 1
0
        public static void RemoveDefaultDiscriminator(
            this MappingFragment entityTypeMappingFragment, EntitySetMapping entitySetMapping)
        {
            DebugCheck.NotNull(entityTypeMappingFragment);

            var discriminatorColumn = entityTypeMappingFragment.RemoveDefaultDiscriminatorCondition();

            if (discriminatorColumn != null)
            {
                var table = entityTypeMappingFragment.Table;

                table.Properties
                .Where(c => c.Name.Equals(discriminatorColumn.Name, StringComparison.Ordinal))
                .ToList()
                .Each(table.RemoveMember);
            }

            if (entitySetMapping != null &&
                entityTypeMappingFragment.IsConditionOnlyFragment()
                &&
                !entityTypeMappingFragment.ColumnConditions.Any())
            {
                var entityTypeMapping =
                    entitySetMapping.EntityTypeMappings.Single(
                        etm => etm.MappingFragments.Contains(entityTypeMappingFragment));

                entityTypeMapping.RemoveFragment(entityTypeMappingFragment);

                if (entityTypeMapping.MappingFragments.Count == 0)
                {
                    entitySetMapping.RemoveTypeMapping(entityTypeMapping);
                }
            }
        }
Exemplo n.º 2
0
        public static void RemoveDefaultDiscriminator(
            this MappingFragment entityTypeMappingFragment,
            EntitySetMapping entitySetMapping)
        {
            EdmProperty discriminatorColumn = entityTypeMappingFragment.RemoveDefaultDiscriminatorCondition();

            if (discriminatorColumn != null)
            {
                EntityType table = entityTypeMappingFragment.Table;
                table.Properties.Where <EdmProperty>((Func <EdmProperty, bool>)(c => c.Name.Equals(discriminatorColumn.Name, StringComparison.Ordinal))).ToList <EdmProperty>().Each <EdmProperty>(new Action <EdmProperty>(((StructuralType)table).RemoveMember));
            }
            if (entitySetMapping == null || !entityTypeMappingFragment.IsConditionOnlyFragment() || entityTypeMappingFragment.ColumnConditions.Any <ConditionPropertyMapping>())
            {
                return;
            }
            EntityTypeMapping typeMapping = entitySetMapping.EntityTypeMappings.Single <EntityTypeMapping>((Func <EntityTypeMapping, bool>)(etm => etm.MappingFragments.Contains(entityTypeMappingFragment)));

            typeMapping.RemoveFragment(entityTypeMappingFragment);
            if (typeMapping.MappingFragments.Count != 0)
            {
                return;
            }
            entitySetMapping.RemoveTypeMapping(typeMapping);
        }