-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Migrations: Preserve entity type display name in snapshot #3810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ | |
|
|
||
| namespace Microsoft.Data.Entity.Metadata.Internal | ||
| { | ||
| public class EntityType : | ||
| ConventionalAnnotatable, | ||
| IMutableEntityType, | ||
| ICanGetNavigations, | ||
| IPropertyCountsAccessor, | ||
| public class EntityType : | ||
| ConventionalAnnotatable, | ||
| IMutableEntityType, | ||
| ICanGetNavigations, | ||
| IPropertyCountsAccessor, | ||
| ISnapshotFactorySource | ||
| { | ||
| private static readonly char[] _simpleNameChars = { '.', '+' }; | ||
|
|
@@ -76,7 +76,7 @@ public EntityType([NotNull] string name, [NotNull] Model model, ConfigurationSou | |
|
|
||
| _properties = new SortedDictionary<string, Property>(new PropertyComparer(this)); | ||
| #if DEBUG | ||
| DebugName = DisplayName(); | ||
| DebugName = EntityTypeExtensions.DisplayName(this); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this.DisplayName() ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which is the lesser of two evils..?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for this |
||
| #endif | ||
| } | ||
|
|
||
|
|
@@ -113,7 +113,7 @@ public virtual Type ClrType | |
| || GetDirectlyDerivedTypes().Any() | ||
| || GetProperties().Any()) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.EntityTypeInUse(DisplayName())); | ||
| throw new InvalidOperationException(CoreStrings.EntityTypeInUse(EntityTypeExtensions.DisplayName(this))); | ||
| } | ||
|
|
||
| _typeOrName = value; | ||
|
|
@@ -253,23 +253,6 @@ public virtual string Name | |
| } | ||
| } | ||
|
|
||
| public virtual string DisplayName() | ||
| { | ||
| if (ClrType != null) | ||
| { | ||
| return ClrType.DisplayName(false) ?? ParseSimpleName(); | ||
| } | ||
| return ParseSimpleName(); | ||
| } | ||
|
|
||
| private string ParseSimpleName() | ||
| { | ||
| var fullName = (string)_typeOrName; | ||
| var lastDot = fullName.LastIndexOfAny(_simpleNameChars); | ||
|
|
||
| return lastDot > 0 ? fullName.Substring(lastDot + 1) : fullName; | ||
| } | ||
|
|
||
| public override string ToString() => Name; | ||
|
|
||
| public virtual ConfigurationSource GetConfigurationSource() => _configurationSource; | ||
|
|
@@ -304,7 +287,8 @@ public virtual Key SetPrimaryKey( | |
| { | ||
| if (_baseType != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(DisplayName(), _baseType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.DerivedEntityTypeKey(EntityTypeExtensions.DisplayName(this), _baseType.DisplayName())); | ||
| } | ||
|
|
||
| if (_primaryKey != null) | ||
|
|
@@ -394,21 +378,29 @@ public virtual Key AddKey([NotNull] IReadOnlyList<Property> properties, | |
|
|
||
| if (_baseType != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(DisplayName(), _baseType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.DerivedEntityTypeKey(EntityTypeExtensions.DisplayName(this), _baseType.DisplayName())); | ||
| } | ||
|
|
||
| foreach (var property in properties) | ||
| { | ||
| if (FindProperty(property.Name) != property) | ||
| { | ||
| throw new ArgumentException(CoreStrings.KeyPropertiesWrongEntity(Property.Format(properties), DisplayName())); | ||
| throw new ArgumentException( | ||
| CoreStrings.KeyPropertiesWrongEntity( | ||
| Property.Format(properties), | ||
| EntityTypeExtensions.DisplayName(this))); | ||
| } | ||
| } | ||
|
|
||
| var key = FindKey(properties); | ||
| if (key != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DuplicateKey(Property.Format(properties), DisplayName(), key.DeclaringEntityType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.DuplicateKey( | ||
| Property.Format(properties), | ||
| EntityTypeExtensions.DisplayName(this), | ||
| key.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| key = new Key(properties, configurationSource); | ||
|
|
@@ -522,7 +514,11 @@ public virtual ForeignKey AddForeignKey( | |
| var duplicateForeignKey = FindForeignKeysInHierarchy(properties, principalKey, principalEntityType).FirstOrDefault(); | ||
| if (duplicateForeignKey != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DuplicateForeignKey(Property.Format(properties), DisplayName(), duplicateForeignKey.DeclaringEntityType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.DuplicateForeignKey( | ||
| Property.Format(properties), | ||
| EntityTypeExtensions.DisplayName(this), | ||
| duplicateForeignKey.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| var foreignKey = new ForeignKey(properties, principalKey, this, principalEntityType, configurationSource ?? ConfigurationSource.Convention); | ||
|
|
@@ -641,7 +637,7 @@ private ForeignKey RemoveForeignKey([NotNull] ForeignKey foreignKey) | |
| { | ||
| foreignKey.DeclaringEntityType.RemoveNavigation(foreignKey.DependentToPrincipal.Name); | ||
| } | ||
|
|
||
| if (foreignKey.PrincipalToDependent != null) | ||
| { | ||
| foreignKey.PrincipalEntityType.RemoveNavigation(foreignKey.PrincipalToDependent.Name); | ||
|
|
@@ -690,14 +686,20 @@ public virtual Navigation AddNavigation( | |
| } | ||
|
|
||
| throw new InvalidOperationException( | ||
| CoreStrings.DuplicateNavigation(name, DisplayName(), duplicateNavigation.DeclaringEntityType.DisplayName())); | ||
| CoreStrings.DuplicateNavigation( | ||
| name, | ||
| EntityTypeExtensions.DisplayName(this), | ||
| duplicateNavigation.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| var duplicateProperty = FindPropertiesInHierarchy(name).FirstOrDefault(); | ||
| if (duplicateProperty != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.ConflictingProperty(name, DisplayName(), | ||
| duplicateProperty.DeclaringEntityType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.ConflictingProperty( | ||
| name, | ||
| EntityTypeExtensions.DisplayName(this), | ||
| duplicateProperty.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| Debug.Assert(!GetNavigations().Any(n => (n.ForeignKey == foreignKey) && (n.IsDependentToPrincipal() == pointsToPrincipal)), | ||
|
|
@@ -788,14 +790,21 @@ public virtual Index AddIndex([NotNull] IReadOnlyList<Property> properties, | |
| { | ||
| if (FindProperty(property.Name) != property) | ||
| { | ||
| throw new ArgumentException(CoreStrings.IndexPropertiesWrongEntity(Property.Format(properties), DisplayName())); | ||
| throw new ArgumentException( | ||
| CoreStrings.IndexPropertiesWrongEntity( | ||
| Property.Format(properties), | ||
| EntityTypeExtensions.DisplayName(this))); | ||
| } | ||
| } | ||
|
|
||
| var duplicateIndex = FindIndexesInHierarchy(properties).FirstOrDefault(); | ||
| if (duplicateIndex != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DuplicateIndex(Property.Format(properties), DisplayName(), duplicateIndex.DeclaringEntityType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.DuplicateIndex( | ||
| Property.Format(properties), | ||
| EntityTypeExtensions.DisplayName(this), | ||
| duplicateIndex.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| var index = new Index(properties, this, configurationSource); | ||
|
|
@@ -877,14 +886,17 @@ public virtual Property AddProperty([NotNull] string name, | |
| if (duplicateProperty != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.DuplicateProperty( | ||
| name, DisplayName(), duplicateProperty.DeclaringEntityType.DisplayName())); | ||
| name, EntityTypeExtensions.DisplayName(this), duplicateProperty.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| var duplicateNavigation = FindNavigationsInHierarchy(name).FirstOrDefault(); | ||
| if (duplicateNavigation != null) | ||
| { | ||
| throw new InvalidOperationException(CoreStrings.ConflictingNavigation(name, DisplayName(), | ||
| duplicateNavigation.DeclaringEntityType.DisplayName())); | ||
| throw new InvalidOperationException( | ||
| CoreStrings.ConflictingNavigation( | ||
| name, | ||
| EntityTypeExtensions.DisplayName(this), | ||
| duplicateNavigation.DeclaringEntityType.DisplayName())); | ||
| } | ||
|
|
||
| var property = new Property(name, this, configurationSource); | ||
|
|
@@ -998,7 +1010,7 @@ public virtual void PropertyMetadataChanged() | |
| public virtual Func<InternalEntityEntry, ISnapshot> RelationshipSnapshotFactory | ||
| => LazyInitializer.EnsureInitialized(ref _relationshipSnapshotFactory, CreateRelationshipSnapshotFactory); | ||
|
|
||
| private Func<InternalEntityEntry, ISnapshot> CreateRelationshipSnapshotFactory() | ||
| private Func<InternalEntityEntry, ISnapshot> CreateRelationshipSnapshotFactory() | ||
| => new RelationshipSnapshotFactoryFactory().Create(this); | ||
|
|
||
| public virtual Func<InternalEntityEntry, ISnapshot> OriginalValuesFactory | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth putting a comment for this?