Пример #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, 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);
        }