public virtual void AddColumnNameAndTypeConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); var delimitedColumnName = ExtensionsProvider.For(propertyConfiguration.Property).ColumnName != null && ExtensionsProvider.For(propertyConfiguration.Property).ColumnName != propertyConfiguration.Property.Name ? CSharpUtilities.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).ColumnName) : null; var delimitedColumnTypeName = ExtensionsProvider.For(propertyConfiguration.Property).ColumnType != null ? CSharpUtilities.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).ColumnType) : null; if (delimitedColumnName != null) { propertyConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalPropertyBuilderExtensions.HasColumnName), delimitedColumnName) { HasAttributeEquivalent = true }); if (delimitedColumnTypeName == null) { propertyConfiguration.AttributeConfigurations.Add( new AttributeConfiguration(nameof(ColumnAttribute), delimitedColumnName)); } else { propertyConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalPropertyBuilderExtensions.HasColumnType), delimitedColumnTypeName) { HasAttributeEquivalent = true }); propertyConfiguration.AttributeConfigurations.Add( new AttributeConfiguration( nameof(ColumnAttribute), new[] { delimitedColumnName, nameof(ColumnAttribute.TypeName) + " = " + delimitedColumnTypeName })); } } else if (delimitedColumnTypeName != null) { propertyConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalPropertyBuilderExtensions.HasColumnType), delimitedColumnTypeName)); } }
public virtual string ClassName() { var annotatedName = ExtensionsProvider.For(Model).DatabaseName; if (!string.IsNullOrEmpty(annotatedName)) { return(CSharpUtilities.GenerateCSharpIdentifier(annotatedName + DbContextSuffix, null)); } return(DefaultDbContextName); }
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 && ExtensionsProvider.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(); } }
public virtual void AddDefaultExpressionConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).GeneratedValueSql != null) { propertyConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), CSharpUtilities.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).GeneratedValueSql))); } }
public virtual void AddDefaultValueConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue != null) { propertyConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalPropertyBuilderExtensions.HasDefaultValue), CSharpUtilities.GenerateLiteral( (dynamic)ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue))); } }
public virtual void AddComputedExpressionConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).ComputedValueSql != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), CSharpUtilities.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).ComputedValueSql))); } }
public virtual void AddDefaultValueConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue != null) { propertyConfiguration.FluentApiConfigurations.Add( _configurationFactory.CreateFluentApiConfiguration( /* hasAttributeEquivalent */ false, nameof(RelationalPropertyBuilderExtensions.HasDefaultValue), CSharpUtilities.GenerateLiteral( (dynamic)ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue))); } }
public virtual void AddDefaultExpressionFacetConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).GeneratedValueSql != null) { propertyConfiguration.AddFacetConfiguration( new FacetConfiguration( string.Format(CultureInfo.InvariantCulture, "HasDefaultValueSql({0})", CSharpUtilities.Instance.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).GeneratedValueSql)))); } }
public virtual void AddDefaultValueFacetConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue != null) { propertyConfiguration.AddFacetConfiguration( new FacetConfiguration( string.Format(CultureInfo.InvariantCulture, "HasDefaultValue({0})", CSharpUtilities.Instance.GenerateLiteral( (dynamic)ExtensionsProvider.For(propertyConfiguration.Property).DefaultValue)))); } }
public virtual void AddColumnTypeFacetConfiguration( [NotNull] PropertyConfiguration propertyConfiguration) { Check.NotNull(propertyConfiguration, nameof(propertyConfiguration)); if (ExtensionsProvider.For(propertyConfiguration.Property).ColumnType != null) { propertyConfiguration.AddFacetConfiguration( new FacetConfiguration( string.Format(CultureInfo.InvariantCulture, "HasColumnType({0})", CSharpUtilities.Instance.DelimitString( ExtensionsProvider.For(propertyConfiguration.Property).ColumnType)))); } }
public virtual void AddTableNameConfiguration([NotNull] EntityConfiguration entityConfiguration) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); var entityType = entityConfiguration.EntityType; if (ExtensionsProvider.For(entityType).Schema != null && ExtensionsProvider.For(entityType).Schema != DefaultSchemaName) { var delimitedTableName = CSharpUtilities.DelimitString(ExtensionsProvider.For(entityType).TableName); var delimitedSchemaName = CSharpUtilities.DelimitString(ExtensionsProvider.For(entityType).Schema); entityConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalEntityTypeBuilderExtensions.ToTable), delimitedTableName, delimitedSchemaName) { HasAttributeEquivalent = true }); entityConfiguration.AttributeConfigurations.Add( new AttributeConfiguration( nameof(TableAttribute), delimitedTableName, nameof(TableAttribute.Schema) + " = " + delimitedSchemaName)); } else if (ExtensionsProvider.For(entityType).TableName != null && ExtensionsProvider.For(entityType).TableName != entityType.DisplayName()) { var delimitedTableName = CSharpUtilities.DelimitString(ExtensionsProvider.For(entityType).TableName); entityConfiguration.FluentApiConfigurations.Add( new FluentApiConfiguration( nameof(RelationalEntityTypeBuilderExtensions.ToTable), delimitedTableName) { HasAttributeEquivalent = true }); entityConfiguration.AttributeConfigurations.Add( new AttributeConfiguration( nameof(TableAttribute), delimitedTableName)); } }
public virtual void AddTableNameFacetConfiguration([NotNull] EntityConfiguration entityConfiguration) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); var entityType = entityConfiguration.EntityType; if (ExtensionsProvider.For(entityType).Schema != null && ExtensionsProvider.For(entityType).Schema != "dbo") { entityConfiguration.FacetConfigurations.Add( new FacetConfiguration( string.Format(CultureInfo.InvariantCulture, "ToTable({0}, {1})", CSharpUtilities.Instance.DelimitString(ExtensionsProvider.For(entityType).TableName), CSharpUtilities.Instance.DelimitString(ExtensionsProvider.For(entityType).Schema)))); } else if (ExtensionsProvider.For(entityType).TableName != null && ExtensionsProvider.For(entityType).TableName != entityType.DisplayName()) { entityConfiguration.FacetConfigurations.Add( new FacetConfiguration( string.Format(CultureInfo.InvariantCulture, "ToTable({0})", CSharpUtilities.Instance.DelimitString(ExtensionsProvider.For(entityType).TableName)))); } }