예제 #1
0
        internal void Configure(
            DbDatabaseMapping databaseMapping,
            MappingFragment fragment,
            EntityType entityType)
        {
            IEnumerable <EdmPropertyPath> edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(this.PropertyPath, entityType);

            if (edmPropertyPath.Count <EdmPropertyPath>() > 1)
            {
                throw Error.InvalidNotNullCondition((object)this.PropertyPath.ToString(), (object)entityType.Name);
            }
            EdmProperty column = fragment.ColumnMappings.Where <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => pm.PropertyPath.SequenceEqual <EdmProperty>((IEnumerable <EdmProperty>)edmPropertyPath.Single <EdmPropertyPath>()))).Select <ColumnMappingBuilder, EdmProperty>((Func <ColumnMappingBuilder, EdmProperty>)(pm => pm.ColumnProperty)).SingleOrDefault <EdmProperty>();

            if (column == null || !fragment.Table.Properties.Contains(column))
            {
                throw Error.InvalidNotNullCondition((object)this.PropertyPath.ToString(), (object)entityType.Name);
            }
            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(databaseMapping, entityType, fragment.Table, column))
            {
                column.Nullable = true;
            }
            new System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration()
            {
                IsNullable = new bool?(false),
                OverridableConfigurationParts = OverridableConfigurationParts.OverridableInSSpace
            }.Configure(edmPropertyPath.Single <EdmPropertyPath>().Last <EdmProperty>());
            fragment.AddNullabilityCondition(column, false);
        }
예제 #2
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);
        }
예제 #3
0
        internal void Configure(
            DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType)
        {
            DebugCheck.NotNull(fragment);

            var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType);

            if (edmPropertyPath.Count() > 1)
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            var column
                = fragment.ColumnMappings
                  .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single()))
                  .Select(pm => pm.ColumnProperty)
                  .SingleOrDefault();

            if (column == null ||
                !fragment.Table.Properties.Contains(column))
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(
                    databaseMapping, entityType, fragment.Table, column))
            {
                column.Nullable = true;
            }

            // Make the property required
            var newConfiguration = new PrimitivePropertyConfiguration
            {
                IsNullable = false,
                OverridableConfigurationParts =
                    OverridableConfigurationParts.OverridableInSSpace
            };

            newConfiguration.Configure(edmPropertyPath.Single().Last());

            fragment.AddNullabilityCondition(column, isNull: false);
        }