Ejemplo n.º 1
0
        internal void Configure(
            DbDatabaseMapping databaseMapping,
            MappingFragment fragment,
            EntityType entityType,
            DbProviderManifest providerManifest)
        {
            EdmProperty edmProperty = fragment.Table.Properties.SingleOrDefault <EdmProperty>((Func <EdmProperty, bool>)(c => string.Equals(c.Name, this.Discriminator, StringComparison.Ordinal)));

            if (edmProperty != null && ValueConditionConfiguration.GetMappingFragmentsWithColumnAsDefaultDiscriminator(databaseMapping, fragment.Table, edmProperty).Any <MappingFragment>())
            {
                edmProperty.Name = fragment.Table.Properties.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name)).Uniquify(edmProperty.Name);
                edmProperty      = (EdmProperty)null;
            }
            if (edmProperty == null)
            {
                edmProperty = new EdmProperty(this.Discriminator, providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage))
                {
                    Nullable = false
                };
                TablePrimitiveOperations.AddColumn(fragment.Table, edmProperty);
            }
            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(databaseMapping, entityType, fragment.Table, edmProperty))
            {
                edmProperty.Nullable = true;
            }
            System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration = edmProperty.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration;
            if (this.Value != null)
            {
                this.ConfigureColumnType(providerManifest, configuration, edmProperty);
                fragment.AddDiscriminatorCondition(edmProperty, this.Value);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(edmProperty.TypeName))
                {
                    TypeUsage storeType = providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage);
                    edmProperty.PrimitiveType = (PrimitiveType)storeType.EdmType;
                    edmProperty.MaxLength     = new int?(128);
                    edmProperty.Nullable      = false;
                }
                this.GetOrCreateConfiguration <System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration>().IsNullable = new bool?(true);
                fragment.AddNullabilityCondition(edmProperty, true);
            }
            if (this._configuration == null)
            {
                return;
            }
            string errorMessage;

            if (configuration != null && (configuration.OverridableConfigurationParts & OverridableConfigurationParts.OverridableInCSpace) != OverridableConfigurationParts.OverridableInCSpace && !configuration.IsCompatible(this._configuration, true, out errorMessage))
            {
                throw Error.ConflictingColumnConfiguration((object)edmProperty, (object)fragment.Table, (object)errorMessage);
            }
            if (this._configuration.IsNullable.HasValue)
            {
                edmProperty.Nullable = this._configuration.IsNullable.Value;
            }
            this._configuration.Configure(edmProperty, fragment.Table, providerManifest, false, false);
        }
Ejemplo n.º 2
0
        private PrimitivePropertyConfiguration MergeWithExistingConfiguration(
            EdmProperty property,
            Func <string, Exception> getConflictException,
            bool inCSpace,
            bool fillFromExistingConfiguration)
        {
            PrimitivePropertyConfiguration configuration = property.GetConfiguration() as PrimitivePropertyConfiguration;

            if (configuration == null)
            {
                return(this);
            }
            OverridableConfigurationParts configurationParts = inCSpace ? OverridableConfigurationParts.OverridableInCSpace : OverridableConfigurationParts.OverridableInSSpace;

            if (configuration.OverridableConfigurationParts.HasFlag((Enum)configurationParts) || fillFromExistingConfiguration)
            {
                return(configuration.OverrideFrom(this, inCSpace));
            }
            string errorMessage;

            if (this.OverridableConfigurationParts.HasFlag((Enum)configurationParts) || configuration.IsCompatible(this, inCSpace, out errorMessage))
            {
                return(this.OverrideFrom(configuration, inCSpace));
            }
            throw getConflictException(errorMessage);
        }