Skip to content

Commit

Permalink
Move InternalPropertyBuilder state to Property
Browse files Browse the repository at this point in the history
Part of #3476
  • Loading branch information
AndriySvyryd committed Nov 10, 2015
1 parent 5c2fef8 commit 8ad859e
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ protected virtual InternalPropertyBuilder PropertyBuilder(
Check.NotEmpty(propertyName, nameof(propertyName));

var builder = Builder.Property(propertyName, ConfigurationSource.Explicit);
var clrTypeSet = builder.ClrType(propertyType, ConfigurationSource.Explicit);
var clrTypeSet = builder.HasClrType(propertyType, ConfigurationSource.Explicit);
Debug.Assert(clrTypeSet);
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public virtual InternalRelationshipBuilder Apply(InternalRelationshipBuilder rel
.Entity(property.DeclaringEntityType.Name, ConfigurationSource.Convention)
.Property(property.Name, ConfigurationSource.Convention);

propertyBuilder.UseValueGenerator(false, ConfigurationSource.Convention);
propertyBuilder.RequiresValueGenerator(false, ConfigurationSource.Convention);
propertyBuilder.ValueGenerated(ValueGenerated.Never, ConfigurationSource.Convention);
}

Expand Down Expand Up @@ -88,7 +88,7 @@ private void SetValueGeneration(InternalEntityTypeBuilder entityTypeBuilder, IEn
ConfigurationSource.Convention);
foreach (var propertyBuilder in propertyBuilders)
{
propertyBuilder?.UseValueGenerator(true, ConfigurationSource.Convention);
propertyBuilder?.RequiresValueGenerator(true, ConfigurationSource.Convention);
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ private void SetIdentity(InternalEntityTypeBuilder entityTypeBuilder, Property p
ConfigurationSource.Convention);

propertyBuilder?.ValueGenerated(ValueGenerated.OnAdd, ConfigurationSource.Convention);
propertyBuilder?.UseValueGenerator(true, ConfigurationSource.Convention);
propertyBuilder?.RequiresValueGenerator(true, ConfigurationSource.Convention);
}

public virtual InternalModelBuilder Apply(InternalModelBuilder modelBuilder)
Expand Down
16 changes: 8 additions & 8 deletions src/EntityFramework.Core/Metadata/IMutableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,42 @@ public interface IMutableProperty : IProperty, IMutableAnnotatable
/// <summary>
/// Gets or sets a value indicating whether this property can contain null.
/// </summary>
new bool? IsNullable { get; set; }
new bool IsNullable { get; set; }

/// <summary>
/// Gets or sets a value indicating when a value for this property will be generated by the database. Even when the
/// property is set to be generated by the database, EF may still attempt to save a specific value (rather than
/// having one generated by the database) when the entity is added and a value is assigned, or the property is
/// marked as modified for an existing entity. See <see cref="IsStoreGeneratedAlways"/> for more information.
/// </summary>
new ValueGenerated? ValueGenerated { get; set; }
new ValueGenerated ValueGenerated { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not this property can be modified before the entity is
/// saved to the database. If true, an exception will be thrown if a value is assigned to
/// this property when it is in the <see cref="EntityState.Added"/> state.
/// </summary>
new bool? IsReadOnlyBeforeSave { get; set; }
new bool IsReadOnlyBeforeSave { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not this property can be modified after the entity is
/// saved to the database. If true, an exception will be thrown if a new value is assigned to
/// this property after the entity exists in the database.
/// </summary>
new bool? IsReadOnlyAfterSave { get; set; }
new bool IsReadOnlyAfterSave { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this property requires a <see cref="ValueGenerator"/> to generate
/// values when new entities are added to the context.
/// </summary>
new bool? RequiresValueGenerator { get; set; }
new bool RequiresValueGenerator { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this is a shadow property. A shadow property is one that does not have a
/// corresponding property in the entity class. The current value for the property is stored in
/// the <see cref="ChangeTracker" /> rather than being stored in instances of the entity class.
/// </summary>
new bool? IsShadowProperty { get; set; }
new bool IsShadowProperty { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this property is used as a concurrency token. When a property is configured
Expand All @@ -76,7 +76,7 @@ public interface IMutableProperty : IProperty, IMutableAnnotatable
/// the instance was retrieved from the database. If it has changed, an exception will be thrown and the
/// changes will not be applied to the database.
/// </summary>
new bool? IsConcurrencyToken { get; set; }
new bool IsConcurrencyToken { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not the database will always generate a value for this property.
Expand All @@ -85,6 +85,6 @@ public interface IMutableProperty : IProperty, IMutableAnnotatable
/// (or marked as modified) EF will attempt to save that value to the database rather than letting the
/// database generate one.
/// </summary>
new bool? IsStoreGeneratedAlways { get; set; }
new bool IsStoreGeneratedAlways { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/EntityFramework.Core/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public virtual Key SetPrimaryKey(

foreach (var property in key.Properties)
{
property.IsNullable = null;
property.IsNullable = false;
_properties.Add(property.Name, property);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/EntityFramework.Core/Metadata/Internal/ForeignKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public virtual bool? IsRequired
{
get
{
return Properties.Any(p => p.IsNullable.HasValue)
? !Properties.Any(p => ((IProperty)p).IsNullable) as bool?
return Properties.Any(p => p.GetIsNullableConfigurationSource().HasValue)
? !Properties.Any(p => p.IsNullable) as bool?
: null;
}
set
Expand All @@ -126,9 +126,12 @@ public virtual bool? IsRequired
// If no properties can be made nullable, let it fail
}

foreach (var property in properties)
if (value.HasValue)
{
property.IsNullable = !value;
foreach (var property in properties)
{
property.IsNullable = !value.Value;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,17 @@ private InternalPropertyBuilder Property(
return Add(
propertyName,
(p, c) => p.UpdateConfigurationSource(c),
AddProperty,
Metadata.AddProperty,
p => ConfigureProperty(p.Builder, propertyType, shadowProperty, configurationSource),
configurationSource,
Unignore,
ModelBuilder.ConventionDispatcher.OnPropertyAdded);
}

existingProperty.UpdateConfigurationSource(configurationSource);
if (existingProperty.Builder == null)
{
existingProperty.Builder = new InternalPropertyBuilder(existingProperty, ModelBuilder, existing: true);
}
return ConfigureProperty(existingProperty.Builder, propertyType, shadowProperty, configurationSource);
}

private Property AddProperty(string propertyName, ConfigurationSource configurationSource)
{
var property = Metadata.AddProperty(propertyName, configurationSource);
property.Builder = new InternalPropertyBuilder(property, ModelBuilder, existing: false);
return property;
}

private InternalPropertyBuilder ConfigureProperty(
InternalPropertyBuilder builder, Type propertyType, bool? shadowProperty, ConfigurationSource configurationSource)
{
Expand All @@ -206,13 +195,13 @@ private InternalPropertyBuilder ConfigureProperty(
}

if (propertyType != null
&& !builder.ClrType(propertyType, configurationSource))
&& !builder.HasClrType(propertyType, configurationSource))
{
return null;
}

if (shadowProperty.HasValue
&& !builder.Shadow(shadowProperty.Value, configurationSource))
&& !builder.IsShadow(shadowProperty.Value, configurationSource))
{
return null;
}
Expand Down
Loading

0 comments on commit 8ad859e

Please sign in to comment.