diff --git a/src/EntityFramework.Commands/Migrations/Design/CSharpMigrationOperationGenerator.cs b/src/EntityFramework.Commands/Migrations/Design/CSharpMigrationOperationGenerator.cs index aee19a77a9a..de9dea66602 100644 --- a/src/EntityFramework.Commands/Migrations/Design/CSharpMigrationOperationGenerator.cs +++ b/src/EntityFramework.Commands/Migrations/Design/CSharpMigrationOperationGenerator.cs @@ -113,7 +113,7 @@ protected virtual void Generate([NotNull] AddColumnOperation operation, [NotNull builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -186,7 +186,7 @@ protected virtual void Generate([NotNull] AddForeignKeyOperation operation, [Not builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -223,7 +223,7 @@ protected virtual void Generate([NotNull] AddPrimaryKeyOperation operation, [Not .Append(_code.Literal(operation.Columns)) .Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -260,7 +260,7 @@ protected virtual void Generate([NotNull] AddUniqueConstraintOperation operation .Append(_code.Literal(operation.Columns)) .Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -328,7 +328,7 @@ protected virtual void Generate([NotNull] AlterColumnOperation operation, [NotNu builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -386,7 +386,7 @@ protected virtual void Generate([NotNull] AlterSequenceOperation operation, [Not builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -431,7 +431,7 @@ protected virtual void Generate([NotNull] CreateIndexOperation operation, [NotNu builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -447,7 +447,7 @@ protected virtual void Generate([NotNull] EnsureSchemaOperation operation, [NotN using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -523,7 +523,7 @@ protected virtual void Generate([NotNull] CreateSequenceOperation operation, [No builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -611,7 +611,7 @@ protected virtual void Generate([NotNull] CreateTableOperation operation, [NotNu using (builder.Indent()) { - Annotations(column.Annotations, builder); + Annotations(column.GetAnnotations(), builder); } if (i != operation.Columns.Count - 1) @@ -641,7 +641,7 @@ protected virtual void Generate([NotNull] CreateTableOperation operation, [NotNu using (builder.Indent()) { - Annotations(operation.PrimaryKey.Annotations, builder); + Annotations(operation.PrimaryKey.GetAnnotations(), builder); } builder.AppendLine(";"); @@ -658,7 +658,7 @@ protected virtual void Generate([NotNull] CreateTableOperation operation, [NotNu using (builder.Indent()) { - Annotations(uniqueConstraint.Annotations, builder); + Annotations(uniqueConstraint.GetAnnotations(), builder); } builder.AppendLine(";"); @@ -716,7 +716,7 @@ protected virtual void Generate([NotNull] CreateTableOperation operation, [NotNu builder.Append(")"); - Annotations(foreignKey.Annotations, builder); + Annotations(foreignKey.GetAnnotations(), builder); } builder.AppendLine(";"); @@ -725,7 +725,7 @@ protected virtual void Generate([NotNull] CreateTableOperation operation, [NotNu builder.Append("})"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -752,7 +752,7 @@ protected virtual void Generate([NotNull] DropColumnOperation operation, [NotNul using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -779,7 +779,7 @@ protected virtual void Generate([NotNull] DropForeignKeyOperation operation, [No using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -806,7 +806,7 @@ protected virtual void Generate([NotNull] DropIndexOperation operation, [NotNull using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -833,7 +833,7 @@ protected virtual void Generate([NotNull] DropPrimaryKeyOperation operation, [No using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -849,7 +849,7 @@ protected virtual void Generate([NotNull] DropSchemaOperation operation, [NotNul using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -878,7 +878,7 @@ protected virtual void Generate([NotNull] DropSequenceOperation operation, [NotN using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -907,7 +907,7 @@ protected virtual void Generate([NotNull] DropTableOperation operation, [NotNull using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -934,7 +934,7 @@ protected virtual void Generate([NotNull] DropUniqueConstraintOperation operatio using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -968,7 +968,7 @@ protected virtual void Generate([NotNull] RenameColumnOperation operation, [NotN .Append(_code.Literal(operation.NewName)) .Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -1002,7 +1002,7 @@ protected virtual void Generate([NotNull] RenameIndexOperation operation, [NotNu .Append(_code.Literal(operation.NewName)) .Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -1045,7 +1045,7 @@ protected virtual void Generate([NotNull] RenameSequenceOperation operation, [No builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -1088,7 +1088,7 @@ protected virtual void Generate([NotNull] RenameTableOperation operation, [NotNu builder.Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -1118,7 +1118,7 @@ protected virtual void Generate([NotNull] RestartSequenceOperation operation, [N .Append(_code.Literal(operation.StartValue)) .Append(")"); - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } @@ -1134,7 +1134,7 @@ protected virtual void Generate([NotNull] SqlOperation operation, [NotNull] Inde using (builder.Indent()) { - Annotations(operation.Annotations, builder); + Annotations(operation.GetAnnotations(), builder); } } diff --git a/src/EntityFramework.Commands/Migrations/Design/CSharpSnapshotGenerator.cs b/src/EntityFramework.Commands/Migrations/Design/CSharpSnapshotGenerator.cs index daed1de27a4..b8aab5ecf37 100644 --- a/src/EntityFramework.Commands/Migrations/Design/CSharpSnapshotGenerator.cs +++ b/src/EntityFramework.Commands/Migrations/Design/CSharpSnapshotGenerator.cs @@ -33,7 +33,7 @@ public virtual void Generate( Check.NotNull(model, nameof(model)); Check.NotNull(stringBuilder, nameof(stringBuilder)); - var annotations = model.Annotations.ToArray(); + var annotations = model.GetAnnotations().ToArray(); if (annotations.Length != 0) { stringBuilder.Append(builderName); @@ -240,7 +240,7 @@ protected virtual void GeneratePropertyAnnotations([NotNull] IProperty property, Check.NotNull(property, nameof(property)); Check.NotNull(stringBuilder, nameof(stringBuilder)); - GenerateAnnotations(property.Annotations.ToArray(), stringBuilder); + GenerateAnnotations(property.GetAnnotations().ToArray(), stringBuilder); } protected virtual void GenerateKeys( @@ -284,7 +284,7 @@ protected virtual void GenerateKey( using (stringBuilder.Indent()) { - GenerateAnnotations(key.Annotations.ToArray(), stringBuilder); + GenerateAnnotations(key.GetAnnotations().ToArray(), stringBuilder); } stringBuilder.Append(";"); @@ -324,7 +324,7 @@ protected virtual void GenerateIndex( .Append(".IsUnique()"); } - GenerateAnnotations(index.Annotations.ToArray(), stringBuilder); + GenerateAnnotations(index.GetAnnotations().ToArray(), stringBuilder); } stringBuilder.Append(";"); @@ -335,7 +335,7 @@ protected virtual void GenerateEntityTypeAnnotations([NotNull] IEntityType entit Check.NotNull(entityType, nameof(entityType)); Check.NotNull(stringBuilder, nameof(stringBuilder)); - var annotations = entityType.Annotations.ToArray(); + var annotations = entityType.GetAnnotations().ToArray(); if (annotations.Any()) { foreach (var annotation in annotations) @@ -441,7 +441,7 @@ protected virtual void GenerateForeignKeyAnnotations([NotNull] IForeignKey forei Check.NotNull(foreignKey, nameof(foreignKey)); Check.NotNull(stringBuilder, nameof(stringBuilder)); - GenerateAnnotations(foreignKey.Annotations.ToArray(), stringBuilder); + GenerateAnnotations(foreignKey.GetAnnotations().ToArray(), stringBuilder); } protected virtual void GenerateAnnotations( diff --git a/src/EntityFramework.Commands/Migrations/Design/MigrationsCodeGenerator.cs b/src/EntityFramework.Commands/Migrations/Design/MigrationsCodeGenerator.cs index b6886ef4400..39ec9ff9252 100644 --- a/src/EntityFramework.Commands/Migrations/Design/MigrationsCodeGenerator.cs +++ b/src/EntityFramework.Commands/Migrations/Design/MigrationsCodeGenerator.cs @@ -109,7 +109,7 @@ private IEnumerable GetAnnotatables(IModel model) private IEnumerable GetAnnotationNamespaces(IEnumerable items) => from i in items - from a in i.Annotations + from a in i.GetAnnotations() where a.Value != null && !IgnoredAnnotations.Contains(a.Name) select a.Value.GetType().Namespace; } diff --git a/src/EntityFramework.Core/Extensions/MutableModelExtensions.cs b/src/EntityFramework.Core/Extensions/MutableModelExtensions.cs index a5715d1c8b8..6d6c334adb2 100644 --- a/src/EntityFramework.Core/Extensions/MutableModelExtensions.cs +++ b/src/EntityFramework.Core/Extensions/MutableModelExtensions.cs @@ -3,6 +3,7 @@ using System; using JetBrains.Annotations; +using Microsoft.Data.Entity.Internal; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Utilities; @@ -34,5 +35,26 @@ public static IMutableEntityType GetOrAddEntityType([NotNull] this IMutableModel return model.FindEntityType(name) ?? model.AddEntityType(name); } + + public static IMutableEntityType GetOrAddEntityType([NotNull] this IMutableModel model, [NotNull] Type type) + => model.FindEntityType(type) ?? model.AddEntityType(type); + + public static IMutableEntityType AddEntityType([NotNull] this IMutableModel model, [NotNull] Type type) + { + Check.NotNull(model, nameof(model)); + Check.NotNull(type, nameof(type)); + + var entityType = model.AddEntityType(type.DisplayName()); + entityType.ClrType = type; + return entityType; + } + + public static IMutableEntityType RemoveEntityType([NotNull] this IMutableModel model, [NotNull] Type type) + { + Check.NotNull(model, nameof(model)); + Check.NotNull(type, nameof(type)); + + return model.RemoveEntityType(type.DisplayName()); + } } } diff --git a/src/EntityFramework.Core/Infrastructure/Annotatable.cs b/src/EntityFramework.Core/Infrastructure/Annotatable.cs index 73a6ba2f81d..98e0a35f13b 100644 --- a/src/EntityFramework.Core/Infrastructure/Annotatable.cs +++ b/src/EntityFramework.Core/Infrastructure/Annotatable.cs @@ -131,7 +131,7 @@ public virtual object this[[NotNull] string annotationName] /// /// Gets all annotations on the current object. /// - public virtual IEnumerable Annotations + public virtual IEnumerable GetAnnotations() => _annotations.HasValue ? (IEnumerable)_annotations.Value : ImmutableList.Empty; @@ -144,7 +144,7 @@ private class AnnotationComparer : IComparer /// /// Gets all annotations on the current object. /// - IEnumerable IAnnotatable.Annotations => Annotations; + IEnumerable IAnnotatable.GetAnnotations() => GetAnnotations(); /// /// Gets the annotation with the given name, returning null if it does not exist. diff --git a/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs b/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs index 1fe4cd1c751..9465c505020 100644 --- a/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs +++ b/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs @@ -40,6 +40,6 @@ public interface IAnnotatable /// /// Gets all annotations on the current object. /// - IEnumerable Annotations { get; } + IEnumerable GetAnnotations(); } } diff --git a/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs b/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs index 6d8fee80086..2cbefdd1a0a 100644 --- a/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs +++ b/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs @@ -30,7 +30,7 @@ public interface IMutableAnnotatable : IAnnotatable /// /// Gets all annotations on the current object. /// - new IEnumerable Annotations { get; } + new IEnumerable GetAnnotations(); /// /// Adds an annotation to this object. Throws if an annotation with the specified name already exists. @@ -56,4 +56,4 @@ public interface IMutableAnnotatable : IAnnotatable /// The annotation that was removed. Annotation RemoveAnnotation([NotNull] string annotationName); } -} \ No newline at end of file +} diff --git a/src/EntityFramework.Core/Metadata/IMutableEntityType.cs b/src/EntityFramework.Core/Metadata/IMutableEntityType.cs index 03ec0a14d88..691d3292e75 100644 --- a/src/EntityFramework.Core/Metadata/IMutableEntityType.cs +++ b/src/EntityFramework.Core/Metadata/IMutableEntityType.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using JetBrains.Annotations; @@ -17,6 +18,18 @@ namespace Microsoft.Data.Entity.Metadata /// public interface IMutableEntityType : IEntityType, IMutableAnnotatable { + /// + /// + /// Gets or sets the CLR class that is used to represent instances of this entity. Returns null if the entity does not + /// have a corresponding CLR class (known as a shadow entity). + /// + /// + /// Shadow entities are not currently supported in a model that is used at runtime with a . + /// Therefore, shadow entities will only exist in migration model snapshots, etc. + /// + /// + new Type ClrType { get; [param: CanBeNull] set; } + /// /// Gets the model this entity belongs to. /// @@ -123,7 +136,7 @@ IMutableForeignKey AddForeignKey( /// /// IMutableForeignKey RemoveForeignKey([NotNull] IReadOnlyList properties, [NotNull] IKey principalKey, [NotNull] IEntityType principalEntityType); - + /// /// Adds an index to this entity. /// diff --git a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs index 2f73ddcddb0..d30c8f7e36c 100644 --- a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs +++ b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs @@ -31,27 +31,13 @@ private readonly SortedDictionary, Index> _indexes private readonly SortedDictionary, Key> _keys = new SortedDictionary, Key>(PropertyListComparer.Instance); - private readonly object _typeOrName; + private object _typeOrName; private Key _primaryKey; private EntityType _baseType; private bool _useEagerSnapshots; - - /// - /// Creates a new metadata object representing an entity type associated with the given .NET type. - /// - /// The .NET entity type that this metadata object represents. - /// The model associated with this entity type. - public EntityType([NotNull] Type type, [NotNull] Model model) - : this((object)Check.NotNull(type, nameof(type)), - Check.NotNull(model, nameof(model))) - { - Check.ValidEntityType(type, nameof(type)); - - _useEagerSnapshots = !this.HasPropertyChangingNotifications(); - } - + /// /// Creates a new metadata object representing an entity type that will participate in shadow-state /// such that there is no underlying .NET type corresponding to this metadata object. @@ -59,15 +45,11 @@ public EntityType([NotNull] Type type, [NotNull] Model model) /// The name of the shadow-state entity type. /// The model associated with this entity type. public EntityType([NotNull] string name, [NotNull] Model model) - : this((object)Check.NotEmpty(name, nameof(name)), - Check.NotNull(model, nameof(model))) { - } - - private EntityType(object typeOrName, Model model) - { - _typeOrName = typeOrName; + Check.NotEmpty(name, nameof(name)); + Check.NotNull(model, nameof(model)); + _typeOrName = name; Model = model; _properties = new SortedDictionary(new PropertyComparer(this)); @@ -75,12 +57,47 @@ private EntityType(object typeOrName, Model model) DebugName = DisplayName(); #endif } - #if DEBUG private string DebugName { get; set; } #endif - public virtual Type ClrType => _typeOrName as Type; + Type IEntityType.ClrType => ClrType; + + /// + /// Gets or sets the associated .NET type. + /// + public virtual Type ClrType + { + get { return _typeOrName as Type; } + set + { + if (value == null) + { + _typeOrName = Name; + _useEagerSnapshots = false; + } + else + { + Check.ValidEntityType(value, nameof(value)); + + if (Name != value.DisplayName()) + { + // Don't use DisplayName for the second argument as it could be ambiguous + throw new InvalidOperationException(CoreStrings.ClrTypeWrongName(value.DisplayName(), Name)); + } + + if (BaseType != null + || GetDirectlyDerivedTypes().Any() + || GetProperties().Any()) + { + throw new InvalidOperationException(CoreStrings.EntityTypeInUse(DisplayName())); + } + + _typeOrName = value; + _useEagerSnapshots = !this.HasPropertyChangingNotifications(); + } + } + } public virtual Model Model { get; } diff --git a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs index 8e58d300c8e..741198885a4 100644 --- a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs +++ b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs @@ -63,7 +63,7 @@ private bool HasAnnotation( protected virtual void MergeAnnotationsFrom([NotNull] InternalMetadataBuilder annotatableBuilder) { - foreach (var annotation in annotatableBuilder.Metadata.Annotations) + foreach (var annotation in annotatableBuilder.Metadata.GetAnnotations()) { ConfigurationSource annotationSource; if (!annotatableBuilder._annotationSources.Value.TryGetValue(annotation.Name, out annotationSource)) diff --git a/src/EntityFramework.Core/Metadata/Internal/Model.cs b/src/EntityFramework.Core/Metadata/Internal/Model.cs index 3876f0975ff..4eebcaaedb8 100644 --- a/src/EntityFramework.Core/Metadata/Internal/Model.cs +++ b/src/EntityFramework.Core/Metadata/Internal/Model.cs @@ -17,13 +17,6 @@ public class Model : Annotatable, IMutableModel private ImmutableSortedSet _entities = ImmutableSortedSet.Empty.WithComparer(new EntityTypeNameComparer()); - public virtual EntityType AddEntityType([NotNull] Type type) - { - Check.NotNull(type, nameof(type)); - - return AddEntityType(new EntityType(type, this)); - } - public virtual EntityType AddEntityType([NotNull] string name) { Check.NotEmpty(name, nameof(name)); @@ -31,6 +24,8 @@ public virtual EntityType AddEntityType([NotNull] string name) return AddEntityType(new EntityType(name, this)); } + public virtual EntityType AddEntityType([NotNull] Type type) => (EntityType)((IMutableModel)this).AddEntityType(type); + private EntityType AddEntityType(EntityType entityType) { var previousLength = _entities.Count; @@ -119,15 +114,11 @@ private EntityType RemoveEntityType([NotNull] EntityType entityType) public virtual IReadOnlyList GetEntityTypes() => _entities; IEntityType IModel.FindEntityType(string name) => FindEntityType(name); - IEnumerable IModel.GetEntityTypes() => GetEntityTypes(); IMutableEntityType IMutableModel.AddEntityType(string name) => AddEntityType(name); - IReadOnlyList IMutableModel.GetEntityTypes() => GetEntityTypes(); - IMutableEntityType IMutableModel.FindEntityType(string name) => FindEntityType(name); - IMutableEntityType IMutableModel.RemoveEntityType(string name) => RemoveEntityType(name); } } diff --git a/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs b/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs index 121e28d767f..3f305b989c5 100644 --- a/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs +++ b/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs @@ -1100,6 +1100,22 @@ public static string NavigationForWrongForeignKey([CanBeNull] object navigation, return string.Format(CultureInfo.CurrentCulture, GetString("NavigationForWrongForeignKey", "navigation", "entityType", "targetFk", "actualFk"), navigation, entityType, targetFk, actualFk); } + /// + /// The specified CLR type '{clrType}' does not match the entity type name '{entity}'. + /// + public static string ClrTypeWrongName([CanBeNull] object clrType, [CanBeNull] object entity) + { + return string.Format(CultureInfo.CurrentCulture, GetString("ClrTypeWrongName", "clrType", "entity"), clrType, entity); + } + + /// + /// The CLR type cannot be set on the entity type '{entityType}' because it has members, base entity type or derived entity types. + /// + public static string EntityTypeInUse([CanBeNull] object entityType) + { + return string.Format(CultureInfo.CurrentCulture, GetString("EntityTypeInUse", "entityType"), entityType); + } + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/EntityFramework.Core/Properties/CoreStrings.resx b/src/EntityFramework.Core/Properties/CoreStrings.resx index 0ae3d901823..e905b9dee37 100644 --- a/src/EntityFramework.Core/Properties/CoreStrings.resx +++ b/src/EntityFramework.Core/Properties/CoreStrings.resx @@ -525,4 +525,10 @@ The navigation property '{navigation}' on entity type '{entityType}' cannot be associated with foreign key {targetFk} because it was created for foreign key {actualFk}. + + The specified CLR type '{clrType}' does not match the entity type name '{entity}'. + + + The CLR type cannot be set on the entity type '{entityType}' because it has members, base entity type or derived entity types. + \ No newline at end of file diff --git a/src/EntityFramework.Relational/Metadata/Sequence.cs b/src/EntityFramework.Relational/Metadata/Sequence.cs index b9aa1e86552..de33545ee9b 100644 --- a/src/EntityFramework.Relational/Metadata/Sequence.cs +++ b/src/EntityFramework.Relational/Metadata/Sequence.cs @@ -76,7 +76,7 @@ public static IEnumerable GetSequences([NotNull] IModel model, [NotNu var startsWith = annotationPrefix + RelationalAnnotationNames.Sequence; - return model.Annotations + return model.GetAnnotations() .Where(a => a.Name.StartsWith(startsWith)) .Select(a => new Sequence(model, a.Name)); } diff --git a/test/EntityFramework.Commands.FunctionalTests/Migrations/ModelSnapshotTest.cs b/test/EntityFramework.Commands.FunctionalTests/Migrations/ModelSnapshotTest.cs index 95077db7d86..0f4f1566342 100644 --- a/test/EntityFramework.Commands.FunctionalTests/Migrations/ModelSnapshotTest.cs +++ b/test/EntityFramework.Commands.FunctionalTests/Migrations/ModelSnapshotTest.cs @@ -65,7 +65,7 @@ public void Model_annotations_are_stored_in_snapshot() ", o => { - Assert.Equal(1, o.Annotations.Count()); + Assert.Equal(1, o.GetAnnotations().Count()); Assert.Equal("AnnotationValue", o["AnnotationName"]); }); } @@ -130,7 +130,7 @@ public void EntityType_annotations_are_stored_in_snapshot() ", o => { - Assert.Equal(1, o.GetEntityTypes().First().Annotations.Count()); + Assert.Equal(1, o.GetEntityTypes().First().GetAnnotations().Count()); Assert.Equal("AnnotationValue", o.GetEntityTypes().First()["AnnotationName"]); }); } diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/Extensions.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/Extensions.cs index 4f31a562833..039b7958dc6 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/Extensions.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/Extensions.cs @@ -92,7 +92,7 @@ private static void CloneProperties(IEntityType sourceEntityType, EntityType tar clonedProperty.ValueGenerated = property.ValueGenerated; clonedProperty.IsReadOnlyBeforeSave = property.IsReadOnlyBeforeSave; clonedProperty.IsReadOnlyAfterSave = property.IsReadOnlyAfterSave; - property.Annotations.ForEach(annotation => clonedProperty[annotation.Name] = annotation.Value); + property.GetAnnotations().ForEach(annotation => clonedProperty[annotation.Name] = annotation.Value); } } @@ -106,7 +106,7 @@ private static void CloneKeys(IEntityType sourceEntityType, EntityType targetEnt { targetEntityType.SetPrimaryKey(clonedKey.Properties); } - key.Annotations.ForEach(annotation => clonedKey[annotation.Name] = annotation.Value); + key.GetAnnotations().ForEach(annotation => clonedKey[annotation.Name] = annotation.Value); } } @@ -117,7 +117,7 @@ private static void CloneIndexes(IEntityType sourceEntityType, EntityType target var clonedIndex = targetEntityType.AddIndex( index.Properties.Select(p => targetEntityType.FindProperty(p.Name)).ToList()); clonedIndex.IsUnique = index.IsUnique; - index.Annotations.ForEach(annotation => clonedIndex[annotation.Name] = annotation.Value); + index.GetAnnotations().ForEach(annotation => clonedIndex[annotation.Name] = annotation.Value); } } @@ -132,7 +132,7 @@ private static void CloneForeignKeys(IEntityType sourceEntityType, EntityType ta targetPrincipalEntityType); clonedForeignKey.IsUnique = foreignKey.IsUnique; clonedForeignKey.IsRequired = foreignKey.IsRequired; - foreignKey.Annotations.ForEach(annotation => clonedForeignKey[annotation.Name] = annotation.Value); + foreignKey.GetAnnotations().ForEach(annotation => clonedForeignKey[annotation.Name] = annotation.Value); } } @@ -150,7 +150,7 @@ private static void CloneNavigations(IEntityType sourceEntityType, EntityType ta var clonedNavigation = navigation.IsDependentToPrincipal() ? targetForeignKey.HasDependentToPrincipal(navigation.Name) : targetForeignKey.HasPrincipalToDependent(navigation.Name); - navigation.Annotations.ForEach(annotation => clonedNavigation[annotation.Name] = annotation.Value); + navigation.GetAnnotations().ForEach(annotation => clonedNavigation[annotation.Name] = annotation.Value); } } } diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/ForeignKeyComparer.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/ForeignKeyComparer.cs index 2d62ce2a394..7cc6681534b 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/ForeignKeyComparer.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/ForeignKeyComparer.cs @@ -41,7 +41,7 @@ public bool Equals(IForeignKey x, IForeignKey y) && (!_compareNavigations || (new NavigationComparer(_compareAnnotations).Equals(x.DependentToPrincipal, y.DependentToPrincipal) && new NavigationComparer(_compareAnnotations).Equals(x.PrincipalToDependent, y.PrincipalToDependent))) - && (!_compareAnnotations || x.Annotations.SequenceEqual(y.Annotations, AnnotationComparer.Instance)); + && (!_compareAnnotations || x.GetAnnotations().SequenceEqual(y.GetAnnotations(), AnnotationComparer.Instance)); } public int GetHashCode(IForeignKey obj) => PropertyListComparer.Instance.GetHashCode(obj.Properties); diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/IndexComparer.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/IndexComparer.cs index 2f82db0cad2..9a58e2c85f1 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/IndexComparer.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/IndexComparer.cs @@ -33,7 +33,7 @@ public bool Equals(IIndex x, IIndex y) return PropertyListComparer.Instance.Equals(x.Properties, y.Properties) && x.IsUnique == y.IsUnique - && (!_compareAnnotations || x.Annotations.SequenceEqual(y.Annotations, AnnotationComparer.Instance)); + && (!_compareAnnotations || x.GetAnnotations().SequenceEqual(y.GetAnnotations(), AnnotationComparer.Instance)); } public int GetHashCode(IIndex obj) => PropertyListComparer.Instance.GetHashCode(obj.Properties); diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/KeyComparer.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/KeyComparer.cs index 934bb25f452..0531591a06e 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/KeyComparer.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/KeyComparer.cs @@ -32,7 +32,7 @@ public bool Equals(IKey x, IKey y) } return PropertyListComparer.Instance.Equals(x.Properties, y.Properties) - && (!_compareAnnotations || x.Annotations.SequenceEqual(y.Annotations, AnnotationComparer.Instance)); + && (!_compareAnnotations || x.GetAnnotations().SequenceEqual(y.GetAnnotations(), AnnotationComparer.Instance)); } public int GetHashCode(IKey obj) => PropertyListComparer.Instance.GetHashCode(obj.Properties); diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/NavigationComparer.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/NavigationComparer.cs index 790ccc468be..2e2dddfab96 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/NavigationComparer.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/NavigationComparer.cs @@ -32,7 +32,7 @@ public bool Equals(INavigation x, INavigation y) } return x.Name == y.Name - && (!_compareAnnotations || x.Annotations.SequenceEqual(y.Annotations, AnnotationComparer.Instance)); + && (!_compareAnnotations || x.GetAnnotations().SequenceEqual(y.GetAnnotations(), AnnotationComparer.Instance)); } public int GetHashCode(INavigation obj) => obj.Name.GetHashCode(); diff --git a/test/EntityFramework.Core.FunctionalTests/TestUtilities/PropertyComparer.cs b/test/EntityFramework.Core.FunctionalTests/TestUtilities/PropertyComparer.cs index 8cc47eaecc8..eed35107d19 100644 --- a/test/EntityFramework.Core.FunctionalTests/TestUtilities/PropertyComparer.cs +++ b/test/EntityFramework.Core.FunctionalTests/TestUtilities/PropertyComparer.cs @@ -41,7 +41,7 @@ public bool Equals(IProperty x, IProperty y) && x.ValueGenerated == y.ValueGenerated && x.IsReadOnlyBeforeSave == y.IsReadOnlyBeforeSave && x.IsReadOnlyAfterSave == y.IsReadOnlyAfterSave - && (!_compareAnnotations ||x.Annotations.SequenceEqual(y.Annotations, AnnotationComparer.Instance)); + && (!_compareAnnotations ||x.GetAnnotations().SequenceEqual(y.GetAnnotations(), AnnotationComparer.Instance)); } public int GetHashCode(IProperty obj) => obj.Name.GetHashCode(); diff --git a/test/EntityFramework.Core.Tests/Infrastructure/AnnotatableTest.cs b/test/EntityFramework.Core.Tests/Infrastructure/AnnotatableTest.cs index a5b00568943..a53e565a0b0 100644 --- a/test/EntityFramework.Core.Tests/Infrastructure/AnnotatableTest.cs +++ b/test/EntityFramework.Core.Tests/Infrastructure/AnnotatableTest.cs @@ -27,11 +27,11 @@ public void Can_add_and_remove_annotation() Assert.Same(annotation, annotatable.GetOrAddAnnotation("Foo", "Baz")); - Assert.Equal(new[] { annotation }, annotatable.Annotations.ToArray()); + Assert.Equal(new[] { annotation }, annotatable.GetAnnotations().ToArray()); Assert.Same(annotation, annotatable.RemoveAnnotation(annotation.Name)); - Assert.Empty(annotatable.Annotations); + Assert.Empty(annotatable.GetAnnotations()); Assert.Null(annotatable.RemoveAnnotation(annotation.Name)); Assert.Null(annotatable["Foo"]); Assert.Null(annotatable.FindAnnotation("Foo")); @@ -68,7 +68,7 @@ public void Can_get_and_set_model_annotations() annotatable["Foo"] = null; Assert.Null(annotatable["Foo"]); - Assert.Empty(annotatable.Annotations); + Assert.Empty(annotatable.GetAnnotations()); Assert.Equal( CoreStrings.AnnotationNotFound("Foo"), @@ -83,7 +83,7 @@ public void Annotations_are_ordered_by_name() var annotation1 = annotatable.AddAnnotation("Z", "Foo"); var annotation2 = annotatable.AddAnnotation("A", "Bar"); - Assert.True(new[] { annotation2, annotation1 }.SequenceEqual(annotatable.Annotations)); + Assert.True(new[] { annotation2, annotation1 }.SequenceEqual(annotatable.GetAnnotations())); } } } diff --git a/test/EntityFramework.Core.Tests/Metadata/EntityTypeExtensionsTest.cs b/test/EntityFramework.Core.Tests/Metadata/EntityTypeExtensionsTest.cs index b9080ccea93..8f8244def8f 100644 --- a/test/EntityFramework.Core.Tests/Metadata/EntityTypeExtensionsTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/EntityTypeExtensionsTest.cs @@ -94,7 +94,7 @@ public void Can_determine_whether_IsAssignableFrom() [Fact] public void Can_get_proper_table_name_for_generic_entityType() { - var entityType = new EntityType(typeof(A), new Model()); + var entityType = new Model().AddEntityType(typeof(A)); Assert.Equal( "A", diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs index 3d479d92ab9..ce0eb8bb366 100644 --- a/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs @@ -1118,19 +1118,67 @@ public void Adding_an_index_throws_when_grandchild_type_has_index_on_same_proper [Fact] public void Can_create_entity_type() { - var model = new Model(); - var entityType = model.AddEntityType(typeof(Customer)); + var entityType = new Model().AddEntityType(typeof(Customer)); + + Assert.Equal(typeof(Customer).FullName, entityType.Name); + Assert.Same(typeof(Customer), entityType.ClrType); + } + + [Fact] + public void Can_set_and_reset_CLR_type() + { + var entityType = new Model().AddEntityType(typeof(Customer).DisplayName()); + + Assert.Equal(typeof(Customer).FullName, entityType.Name); + Assert.Null(entityType.ClrType); + + entityType.ClrType = typeof(Customer); Assert.Equal(typeof(Customer).FullName, entityType.Name); Assert.Same(typeof(Customer), entityType.ClrType); + + entityType.ClrType = null; + + Assert.Equal(typeof(Customer).FullName, entityType.Name); + Assert.Null(entityType.ClrType); + } + + [Fact] + public void Cannot_set_CLR_type_if_name_does_not_match() + { + var entityType = new Model().AddEntityType(typeof(Customer).Name); + + Assert.Equal(CoreStrings.ClrTypeWrongName(typeof(Customer).DisplayName(), typeof(Customer).Name), + Assert.Throws(() => entityType.ClrType = typeof(Customer)).Message); + } + + [Fact] + public void Cannot_set_CLR_type_if_base_type_derived_type_or_properties_set() + { + var model = new Model(); + var entityType = model.AddEntityType(typeof(Customer).DisplayName()); + + entityType.AddProperty("Blah"); + Assert.Equal(CoreStrings.EntityTypeInUse(entityType.DisplayName()), + Assert.Throws(() => entityType.ClrType = typeof(Customer)).Message); + + entityType.RemoveProperty("Blah"); + entityType.BaseType = model.AddEntityType("Base"); + Assert.Equal(CoreStrings.EntityTypeInUse(entityType.DisplayName()), + Assert.Throws(() => entityType.ClrType = typeof(Customer)).Message); + + entityType.BaseType = null; + model.AddEntityType("Derived").BaseType = entityType; + Assert.Equal(CoreStrings.EntityTypeInUse(entityType.DisplayName()), + Assert.Throws(() => entityType.ClrType = typeof(Customer)).Message); } [Fact] public void Display_name_is_prettified_CLR_name() { - Assert.Equal("EntityTypeTest", new EntityType(typeof(EntityTypeTest), new Model()).DisplayName()); - Assert.Equal("Customer", new EntityType(typeof(Customer), new Model()).DisplayName()); - Assert.Equal("List", new EntityType(typeof(List), new Model()).DisplayName()); + Assert.Equal("EntityTypeTest", new Model().AddEntityType(typeof(EntityTypeTest)).DisplayName()); + Assert.Equal("Customer", new Model().AddEntityType(typeof(Customer)).DisplayName()); + Assert.Equal("List", new Model().AddEntityType(typeof(List)).DisplayName()); } [Fact] @@ -1145,9 +1193,9 @@ public void Display_name_is_part_of_name_following_final_separator_when_no_CLR_t [Fact] public void Name_is_prettified_CLR_full_name() { - Assert.Equal("Microsoft.Data.Entity.Metadata.Internal.EntityTypeTest", new EntityType(typeof(EntityTypeTest), new Model()).Name); - Assert.Equal("Microsoft.Data.Entity.Metadata.Internal.EntityTypeTest+Customer", new EntityType(typeof(Customer), new Model()).Name); - Assert.Equal("System.Collections.Generic.List", new EntityType(typeof(List), new Model()).Name); + Assert.Equal("Microsoft.Data.Entity.Metadata.Internal.EntityTypeTest", new Model().AddEntityType(typeof(EntityTypeTest)).Name); + Assert.Equal("Microsoft.Data.Entity.Metadata.Internal.EntityTypeTest+Customer", new Model().AddEntityType(typeof(Customer)).Name); + Assert.Equal("System.Collections.Generic.List", new Model().AddEntityType(typeof(List)).Name); } [Fact] @@ -1756,7 +1804,7 @@ public void Can_add_and_remove_navigations() Assert.Same(customerNavigation, orderType.GetNavigations().Single()); Assert.Same(ordersNavigation, customerType.GetNavigations().Single()); - + Assert.Same(customerNavigation, customerForeignKey.HasDependentToPrincipal(null)); Assert.Null(customerForeignKey.HasDependentToPrincipal(null)); Assert.Empty(orderType.GetNavigations()); @@ -1808,7 +1856,7 @@ public void Can_get_navigation_and_can_try_get_navigation() Assert.Null(orderType.FindNavigation("Nose")); } - + [Fact] public void Adding_a_new_navigation_with_a_name_that_conflicts_with_a_property_throws() { @@ -2528,7 +2576,7 @@ public void Indexes_are_ordered_by_property_count_then_property_names() [Fact] public void Lazy_original_values_are_used_for_full_notification_and_shadow_enties() { - Assert.False(new EntityType(typeof(FullNotificationEntity), new Model()).UseEagerSnapshots); + Assert.False(new Model().AddEntityType(typeof(FullNotificationEntity)).UseEagerSnapshots); } [Fact] @@ -2537,41 +2585,53 @@ public void Lazy_original_values_are_used_for_shadow_enties() Assert.False(new EntityType("Z'ha'dum", new Model()).UseEagerSnapshots); } + [Fact] + public void Lazy_original_values_are_used_for_enties_that_are_made_shadow() + { + var entityType = new Model().AddEntityType(typeof(ChangedOnlyEntity)); + entityType.ClrType = null; + Assert.False(entityType.UseEagerSnapshots); + } + [Fact] public void Eager_original_values_are_used_for_enties_that_only_implement_INotifyPropertyChanged() { - Assert.True(new EntityType(typeof(ChangedOnlyEntity), new Model()).UseEagerSnapshots); + Assert.True(new Model().AddEntityType(typeof(ChangedOnlyEntity)).UseEagerSnapshots); } [Fact] public void Eager_original_values_are_used_for_enties_that_do_no_notification() { - Assert.True(new EntityType(typeof(Customer), new Model()).UseEagerSnapshots); + Assert.True(new Model().AddEntityType(typeof(Customer)).UseEagerSnapshots); } [Fact] public void Lazy_original_values_can_be_switched_off() { - Assert.False(new EntityType(typeof(FullNotificationEntity), new Model()) { UseEagerSnapshots = false }.UseEagerSnapshots); + var entityType = new Model().AddEntityType(typeof(FullNotificationEntity)); + entityType.UseEagerSnapshots = false; + Assert.False(entityType.UseEagerSnapshots); } [Fact] public void Lazy_original_values_can_be_switched_on_but_only_if_entity_does_not_require_eager_values() { - var entityType = new EntityType(typeof(FullNotificationEntity), new Model()) { UseEagerSnapshots = true }; + var entityType = new Model().AddEntityType(typeof(FullNotificationEntity)); + entityType.UseEagerSnapshots = true; entityType.UseEagerSnapshots = false; Assert.False(entityType.UseEagerSnapshots); + entityType = new Model().AddEntityType(typeof(ChangedOnlyEntity)); Assert.Equal( CoreStrings.EagerOriginalValuesRequired(typeof(ChangedOnlyEntity).FullName), - Assert.Throws(() => new EntityType(typeof(ChangedOnlyEntity), new Model()) { UseEagerSnapshots = false }).Message); + Assert.Throws(() => entityType.UseEagerSnapshots = false).Message); } [Fact] public void All_properties_have_original_value_indexes_when_using_eager_original_values() { - var entityType = new EntityType(typeof(FullNotificationEntity), new Model()) { UseEagerSnapshots = true }; - + var entityType = new Model().AddEntityType(typeof(FullNotificationEntity)); + entityType.UseEagerSnapshots = true; entityType.AddProperty(FullNotificationEntity.NameProperty); entityType.AddProperty(FullNotificationEntity.IdProperty); diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs index db01b3b775d..07ad14f52a2 100644 --- a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs @@ -23,10 +23,10 @@ public void Can_only_override_lower_source_annotation() Assert.True(builder.HasAnnotation("Foo", "1", ConfigurationSource.Convention)); Assert.True(builder.HasAnnotation("Foo", "2", ConfigurationSource.DataAnnotation)); - Assert.Equal("2", metadata.Annotations.Single().Value); + Assert.Equal("2", metadata.GetAnnotations().Single().Value); Assert.False(builder.HasAnnotation("Foo", "1", ConfigurationSource.Convention)); - Assert.Equal("2", metadata.Annotations.Single().Value); + Assert.Equal("2", metadata.GetAnnotations().Single().Value); } [Fact] @@ -39,10 +39,10 @@ public void Can_only_override_existing_annotation_explicitly() Assert.True(builder.HasAnnotation("Foo", "1", ConfigurationSource.DataAnnotation)); Assert.False(builder.HasAnnotation("Foo", "2", ConfigurationSource.DataAnnotation)); - Assert.Equal("1", metadata.Annotations.Single().Value); + Assert.Equal("1", metadata.GetAnnotations().Single().Value); Assert.True(builder.HasAnnotation("Foo", "2", ConfigurationSource.Explicit)); - Assert.Equal("2", metadata.Annotations.Single().Value); + Assert.Equal("2", metadata.GetAnnotations().Single().Value); } [Fact] @@ -54,10 +54,10 @@ public void Annotation_set_explicitly_can_not_be_removed_by_convention() Assert.False(builder.HasAnnotation("Foo", null, ConfigurationSource.Convention)); - Assert.Equal("1", metadata.Annotations.Single().Value); + Assert.Equal("1", metadata.GetAnnotations().Single().Value); Assert.True(builder.HasAnnotation("Foo", null, ConfigurationSource.Explicit)); - Assert.Equal(0, metadata.Annotations.Count()); + Assert.Equal(0, metadata.GetAnnotations().Count()); } } } diff --git a/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/InternalSqlServerMetadataBuilderExtensionsTest.cs b/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/InternalSqlServerMetadataBuilderExtensionsTest.cs index f4ac3853a5e..bbb6b86fa0d 100644 --- a/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/InternalSqlServerMetadataBuilderExtensionsTest.cs +++ b/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/InternalSqlServerMetadataBuilderExtensionsTest.cs @@ -29,7 +29,7 @@ public void Can_access_model() Assert.False(builder.SqlServer(ConfigurationSource.Convention).ValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)); Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, builder.Metadata.SqlServer().ValueGenerationStrategy); - Assert.Equal(1, builder.Metadata.Annotations.Count( + Assert.Equal(1, builder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -47,7 +47,7 @@ public void Can_access_entity_type() Assert.False(typeBuilder.SqlServer(ConfigurationSource.Convention).ToTable("Splod")); Assert.Equal("Splow", typeBuilder.Metadata.SqlServer().TableName); - Assert.Equal(1, typeBuilder.Metadata.Annotations.Count( + Assert.Equal(1, typeBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -67,7 +67,7 @@ public void Can_access_property() Assert.False(propertyBuilder.SqlServer(ConfigurationSource.Convention).HiLoSequenceName("Splod")); Assert.Equal("Splow", propertyBuilder.Metadata.SqlServer().HiLoSequenceName); - Assert.Equal(1, propertyBuilder.Metadata.Annotations.Count( + Assert.Equal(1, propertyBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -88,7 +88,7 @@ public void Can_access_key() Assert.False(keyBuilder.SqlServer(ConfigurationSource.Convention).Clustered(true)); Assert.False(keyBuilder.Metadata.SqlServer().IsClustered); - Assert.Equal(1, keyBuilder.Metadata.Annotations.Count( + Assert.Equal(1, keyBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -109,7 +109,7 @@ public void Can_access_index() Assert.False(indexBuilder.SqlServer(ConfigurationSource.Convention).Clustered(true)); Assert.False(indexBuilder.Metadata.SqlServer().IsClustered); - Assert.Equal(1, indexBuilder.Metadata.Annotations.Count( + Assert.Equal(1, indexBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -130,7 +130,7 @@ public void Can_access_relationship() Assert.False(relationshipBuilder.SqlServer(ConfigurationSource.Convention).Name("Splod")); Assert.Equal("Splow", relationshipBuilder.Metadata.SqlServer().Name); - Assert.Equal(1, relationshipBuilder.Metadata.Annotations.Count( + Assert.Equal(1, relationshipBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } diff --git a/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/ModelConventions/SqlServerValueGenerationStrategyConventionTest.cs b/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/ModelConventions/SqlServerValueGenerationStrategyConventionTest.cs index 487ce6d3b3c..00b13b4ea7a 100644 --- a/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/ModelConventions/SqlServerValueGenerationStrategyConventionTest.cs +++ b/test/EntityFramework.MicrosoftSqlServer.Tests/Metadata/ModelConventions/SqlServerValueGenerationStrategyConventionTest.cs @@ -16,10 +16,10 @@ public void Annotations_are_added_when_conventional_model_builder_is_used() { var model = SqlServerTestHelpers.Instance.CreateConventionBuilder().Model; - Assert.Equal(1, model.Annotations.Count()); + Assert.Equal(1, model.GetAnnotations().Count()); - Assert.Equal(SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGenerationStrategy, model.Annotations.Single().Name); - Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, model.Annotations.Single().Value); + Assert.Equal(SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGenerationStrategy, model.GetAnnotations().Single().Name); + Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, model.GetAnnotations().Single().Value); } [Fact] @@ -29,7 +29,7 @@ public void Annotations_are_added_when_conventional_model_builder_is_used_with_s .ForSqlServerUseSequenceHiLo() .Model; - var annotations = model.Annotations.OrderBy(a => a.Name); + var annotations = model.GetAnnotations().OrderBy(a => a.Name); Assert.Equal(3, annotations.Count()); Assert.Equal(SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.HiLoSequenceName, annotations.ElementAt(0).Name); diff --git a/test/EntityFramework.Sqlite.Tests/Metadata/Internal/SqliteInternalMetadataBuilderExtensionsTest.cs b/test/EntityFramework.Sqlite.Tests/Metadata/Internal/SqliteInternalMetadataBuilderExtensionsTest.cs index 9e6b0b0f3c8..8446be46a82 100644 --- a/test/EntityFramework.Sqlite.Tests/Metadata/Internal/SqliteInternalMetadataBuilderExtensionsTest.cs +++ b/test/EntityFramework.Sqlite.Tests/Metadata/Internal/SqliteInternalMetadataBuilderExtensionsTest.cs @@ -24,7 +24,7 @@ public void Can_access_model() Assert.Equal(77, builder.Metadata.Sqlite().FindSequence("Mine").IncrementBy); - Assert.Equal(1, builder.Metadata.Annotations.Count( + Assert.Equal(1, builder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -42,7 +42,7 @@ public void Can_access_entity_type() Assert.False(typeBuilder.Sqlite(ConfigurationSource.Convention).ToTable("Splod")); Assert.Equal("Splow", typeBuilder.Metadata.Sqlite().TableName); - Assert.Equal(1, typeBuilder.Metadata.Annotations.Count( + Assert.Equal(1, typeBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -62,7 +62,7 @@ public void Can_access_property() Assert.False(propertyBuilder.Sqlite(ConfigurationSource.Convention).ColumnName("Splod")); Assert.Equal("Splow", propertyBuilder.Metadata.Sqlite().ColumnName); - Assert.Equal(1, propertyBuilder.Metadata.Annotations.Count( + Assert.Equal(1, propertyBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -83,7 +83,7 @@ public void Can_access_key() Assert.False(keyBuilder.Sqlite(ConfigurationSource.Convention).Name("Splod")); Assert.Equal("Splow", keyBuilder.Metadata.Sqlite().Name); - Assert.Equal(1, keyBuilder.Metadata.Annotations.Count( + Assert.Equal(1, keyBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -104,7 +104,7 @@ public void Can_access_index() indexBuilder.Sqlite(ConfigurationSource.Convention).Name("Splod"); Assert.Equal("Splow", indexBuilder.Metadata.Sqlite().Name); - Assert.Equal(1, indexBuilder.Metadata.Annotations.Count( + Assert.Equal(1, indexBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); } @@ -125,7 +125,7 @@ public void Can_access_relationship() Assert.False(relationshipBuilder.Sqlite(ConfigurationSource.Convention).Name("Splod")); Assert.Equal("Splow", relationshipBuilder.Metadata.Sqlite().Name); - Assert.Equal(1, relationshipBuilder.Metadata.Annotations.Count( + Assert.Equal(1, relationshipBuilder.Metadata.GetAnnotations().Count( a => a.Name.StartsWith(SqliteAnnotationNames.Prefix, StringComparison.Ordinal))); }