/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddColumnNameAndTypeConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); var delimitedColumnName = AnnotationProvider.For(propertyConfiguration.Property).ColumnName != null && AnnotationProvider.For(propertyConfiguration.Property).ColumnName != propertyConfiguration.Property.Name ? CSharpUtilities.DelimitString( AnnotationProvider.For(propertyConfiguration.Property).ColumnName) : null; var delimitedColumnTypeName = AnnotationProvider.For(propertyConfiguration.Property).ColumnType != null ? CSharpUtilities.DelimitString( AnnotationProvider.For(propertyConfiguration.Property).ColumnType) : null; if (delimitedColumnName != null && delimitedColumnTypeName != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(RelationalPropertyBuilderExtensions.HasColumnName), delimitedColumnName)); propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(RelationalPropertyBuilderExtensions.HasColumnType), delimitedColumnTypeName)); propertyConfiguration.AttributeConfigurations.Add( _configurationFactory.CreateAttributeConfiguration( nameof(ColumnAttribute), delimitedColumnName, nameof(ColumnAttribute.TypeName) + " = " + delimitedColumnTypeName)); } else if (delimitedColumnName != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(RelationalPropertyBuilderExtensions.HasColumnName), delimitedColumnName)); propertyConfiguration.AttributeConfigurations.Add( _configurationFactory.CreateAttributeConfiguration(nameof(ColumnAttribute), delimitedColumnName)); } else if (delimitedColumnTypeName != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(RelationalPropertyBuilderExtensions.HasColumnType), delimitedColumnTypeName)); propertyConfiguration.AttributeConfigurations.Add( _configurationFactory.CreateAttributeConfiguration( nameof(ColumnAttribute), nameof(ColumnAttribute.TypeName) + " = " + delimitedColumnTypeName)); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddPropertyConfiguration([NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); AddRequiredConfiguration(propertyConfiguration); AddColumnNameAndTypeConfiguration(propertyConfiguration); AddMaxLengthConfiguration(propertyConfiguration); AddDefaultValueConfiguration(propertyConfiguration); AddDefaultExpressionConfiguration(propertyConfiguration); AddComputedExpressionConfiguration(propertyConfiguration); AddValueGeneratedConfiguration(propertyConfiguration); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddValueGeneratedConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (!((Property)propertyConfiguration.Property).GetValueGeneratedConfigurationSource().HasValue) { return; } var valueGenerated = propertyConfiguration.Property.ValueGenerated; switch (valueGenerated) { case ValueGenerated.OnAdd: // If this property is the single integer primary key on the EntityType then // KeyConvention assumes ValueGeneratedOnAdd() so there is no need to add it. if (_keyConvention.FindValueGeneratedOnAddProperty( new List <Property> { (Property)propertyConfiguration.Property }, (EntityType)propertyConfiguration.EntityConfiguration.EntityType) == null && AnnotationProvider.For(propertyConfiguration.Property).DefaultValueSql == null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(PropertyBuilder.ValueGeneratedOnAdd))); } break; case ValueGenerated.OnAddOrUpdate: propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(PropertyBuilder.ValueGeneratedOnAddOrUpdate))); break; case ValueGenerated.Never: propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(PropertyBuilder.ValueGeneratedNever))); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddComputedExpressionConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (AnnotationProvider.For(propertyConfiguration.Property).ComputedColumnSql != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), CSharpUtilities.DelimitString( AnnotationProvider.For(propertyConfiguration.Property).ComputedColumnSql))); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddDefaultValueConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (AnnotationProvider.For(propertyConfiguration.Property).DefaultValue != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(RelationalPropertyBuilderExtensions.HasDefaultValue), CSharpUtilities.GenerateLiteral( (dynamic)AnnotationProvider.For(propertyConfiguration.Property).DefaultValue))); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual PropertyConfiguration GetOrAddPropertyConfiguration( [NotNull] EntityConfiguration entityConfiguration, [NotNull] Property property) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); Check.NotNull(property, nameof(property)); var propertyConfiguration = FindPropertyConfiguration(property); if (propertyConfiguration == null) { propertyConfiguration = new PropertyConfiguration(entityConfiguration, property); PropertyConfigurations.Add(propertyConfiguration); } return(propertyConfiguration); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddMaxLengthConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); var maxLength = propertyConfiguration.Property.GetMaxLength(); if (maxLength.HasValue) { var maxLengthLiteral = CSharpUtilities.GenerateLiteral(maxLength.Value); propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(PropertyBuilder.HasMaxLength), maxLengthLiteral)); propertyConfiguration.AttributeConfigurations.Add( _configurationFactory.CreateAttributeConfiguration(nameof(MaxLengthAttribute), maxLengthLiteral)); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddValueGeneratedConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); var valueGenerated = propertyConfiguration.Property.ValueGenerated; if (!((Property)propertyConfiguration.Property).GetValueGeneratedConfigurationSource().HasValue || _valueGeneratorConvention.GetValueGenerated((Property)propertyConfiguration.Property) == valueGenerated) { return; } string methodName; switch (valueGenerated) { case ValueGenerated.OnAdd: methodName = nameof(PropertyBuilder.ValueGeneratedOnAdd); break; case ValueGenerated.OnAddOrUpdate: methodName = nameof(PropertyBuilder.ValueGeneratedOnAddOrUpdate); break; case ValueGenerated.Never: methodName = nameof(PropertyBuilder.ValueGeneratedNever); break; default: throw new ArgumentOutOfRangeException(); } propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, methodName)); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void AddRequiredConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (!propertyConfiguration.Property.IsNullable && propertyConfiguration.Property.ClrType.IsNullableType()) { var entityKeyProperties = ((EntityType)propertyConfiguration.EntityConfiguration.EntityType) .FindPrimaryKey()?.Properties ?? Enumerable.Empty <Property>(); if (!entityKeyProperties.Contains(propertyConfiguration.Property)) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ true, nameof(PropertyBuilder.IsRequired))); propertyConfiguration.AttributeConfigurations.Add( _configurationFactory.CreateAttributeConfiguration(nameof(RequiredAttribute))); } } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual PropertyConfiguration GetOrAddPropertyConfiguration( [NotNull] EntityConfiguration entityConfiguration, [NotNull] Property property) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); Check.NotNull(property, nameof(property)); var propertyConfiguration = FindPropertyConfiguration(property); if (propertyConfiguration == null) { propertyConfiguration = new PropertyConfiguration(entityConfiguration, property); PropertyConfigurations.Add(propertyConfiguration); } return propertyConfiguration; }