From fe245483067db5d2a5cad7de95b7c212a42a5494 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 12 Nov 2015 14:17:19 -0800 Subject: [PATCH] :bug: object is not a valid navigation --- .../Metadata/Internal/EntityType.cs | 4 +- .../Properties/CoreStrings.Designer.cs | 54 +++++++++---------- .../Properties/CoreStrings.resx | 2 +- src/Shared/PropertyInfoExtensions.cs | 3 +- .../Metadata/Internal/EntityTypeTest.cs | 4 +- .../Internal/InternalEntityTypeBuilderTest.cs | 4 +- .../RelationshipDiscoveryConventionTest.cs | 2 + 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs index 38025b31049..885cb4e59a0 100644 --- a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs +++ b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs @@ -289,7 +289,7 @@ public virtual Key SetPrimaryKey( { if (_baseType != null) { - throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(Name)); + throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(Name, _baseType.Name)); } if (_primaryKey != null) @@ -379,7 +379,7 @@ public virtual Key AddKey([NotNull] IReadOnlyList properties, if (_baseType != null) { - throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(Name)); + throw new InvalidOperationException(CoreStrings.DerivedEntityTypeKey(Name, _baseType.Name)); } foreach (var property in properties) diff --git a/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs b/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs index 109e34834ee..271bd07c994 100644 --- a/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs +++ b/src/EntityFramework.Core/Properties/CoreStrings.Designer.cs @@ -52,30 +52,6 @@ public static string InvalidPropertyExpression([CanBeNull] object expression) return string.Format(CultureInfo.CurrentCulture, GetString("InvalidPropertyExpression", "expression"), expression); } - /// - /// Unhandled node type: {nodeType} - /// - public static string UnhandledNodeType([CanBeNull] object nodeType) - { - return string.Format(CultureInfo.CurrentCulture, GetString("UnhandledNodeType", "nodeType"), nodeType); - } - - /// - /// Unhandled expression type: {expressionType} - /// - public static string UnhandledExpressionType([CanBeNull] object expressionType) - { - return string.Format(CultureInfo.CurrentCulture, GetString("UnhandledExpressionType", "expressionType"), expressionType); - } - - /// - /// Unhandled operation: MemberInitExpression binding is not a MemberAssignment - /// - public static string InvalidMemberInitBinding - { - get { return GetString("InvalidMemberInitBinding"); } - } - /// /// The instance of entity type '{entityType}' cannot be tracked because another instance of this type with the same key is already being tracked. For new entities consider using an IIdentityGenerator to generate unique key values. /// @@ -685,11 +661,11 @@ public static string InvalidValueGeneratorFactoryProperty([CanBeNull] object fac } /// - /// The derived type '{derivedType}' cannot have keys other than those declared on the root type. + /// The derived type '{derivedType}' cannot have keys other than those declared on the root type '{rootType}'. /// - public static string DerivedEntityTypeKey([CanBeNull] object derivedType) + public static string DerivedEntityTypeKey([CanBeNull] object derivedType, [CanBeNull] object rootType) { - return string.Format(CultureInfo.CurrentCulture, GetString("DerivedEntityTypeKey", "derivedType"), derivedType); + return string.Format(CultureInfo.CurrentCulture, GetString("DerivedEntityTypeKey", "derivedType", "rootType"), derivedType, rootType); } /// @@ -1028,6 +1004,30 @@ public static string EntityTypeNotFound([CanBeNull] object entityType) return string.Format(CultureInfo.CurrentCulture, GetString("EntityTypeNotFound", "entityType"), entityType); } + /// + /// Unhandled operation: MemberInitExpression binding is not a MemberAssignment + /// + public static string InvalidMemberInitBinding + { + get { return GetString("InvalidMemberInitBinding"); } + } + + /// + /// Unhandled expression type: {expressionType} + /// + public static string UnhandledExpressionType([CanBeNull] object expressionType) + { + return string.Format(CultureInfo.CurrentCulture, GetString("UnhandledExpressionType", "expressionType"), expressionType); + } + + /// + /// Unhandled node type: {nodeType} + /// + public static string UnhandledNodeType([CanBeNull] object nodeType) + { + return string.Format(CultureInfo.CurrentCulture, GetString("UnhandledNodeType", "nodeType"), nodeType); + } + 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 ef0aefa0d0b..9b4584c0e73 100644 --- a/src/EntityFramework.Core/Properties/CoreStrings.resx +++ b/src/EntityFramework.Core/Properties/CoreStrings.resx @@ -361,7 +361,7 @@ The '{factory}' cannot create a value generator for property '{property}' on entity type '{entityType}'. Only integer properties are supported. - The derived type '{derivedType}' cannot have keys other than those declared on the root type. + The derived type '{derivedType}' cannot have keys other than those declared on the root type '{rootType}'. The entity type '{entityType}' cannot inherit from '{baseEntityType}' because '{baseEntityType}' is a descendent of '{entityType}'. diff --git a/src/Shared/PropertyInfoExtensions.cs b/src/Shared/PropertyInfoExtensions.cs index c0c09faf306..1d9b6ce70ab 100644 --- a/src/Shared/PropertyInfoExtensions.cs +++ b/src/Shared/PropertyInfoExtensions.cs @@ -31,7 +31,8 @@ public static Type FindCandidateNavigationPropertyType(this PropertyInfo propert if (isPrimitiveProperty(targetType) || targetType.GetTypeInfo().IsInterface - || targetType.GetTypeInfo().IsValueType) + || targetType.GetTypeInfo().IsValueType + || targetType == typeof(object)) { return null; } diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs index 485f3f270f8..9d9c29bcebc 100644 --- a/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/Internal/EntityTypeTest.cs @@ -476,10 +476,10 @@ public void Adding_keys_throws_when_there_is_a_parent_type() b.HasBaseType(a); Assert.Equal( - CoreStrings.DerivedEntityTypeKey(typeof(B).FullName), + CoreStrings.DerivedEntityTypeKey(typeof(B).FullName, typeof(A).FullName), Assert.Throws(() => b.SetPrimaryKey(b.AddProperty("G"))).Message); Assert.Equal( - CoreStrings.DerivedEntityTypeKey(typeof(B).FullName), + CoreStrings.DerivedEntityTypeKey(typeof(B).FullName, typeof(A).FullName), Assert.Throws(() => b.AddKey(b.AddProperty("E"))).Message); } diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs index 808307de61a..0966e161494 100644 --- a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs @@ -555,7 +555,7 @@ public void Key_throws_for_derived_type() var derivedEntityBuilder = modelBuilder.Entity(typeof(SpecialOrder), ConfigurationSource.Convention); derivedEntityBuilder.HasBaseType(entityBuilder.Metadata, ConfigurationSource.Convention); - Assert.Equal(CoreStrings.DerivedEntityTypeKey(typeof(SpecialOrder).FullName), + Assert.Equal(CoreStrings.DerivedEntityTypeKey(typeof(SpecialOrder).FullName, typeof(Order).FullName), Assert.Throws(() => derivedEntityBuilder.HasKey(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, ConfigurationSource.DataAnnotation)).Message); } @@ -764,7 +764,7 @@ public void PrimaryKey_throws_for_derived_type() var derivedEntityBuilder = modelBuilder.Entity(typeof(SpecialOrder), ConfigurationSource.Convention); derivedEntityBuilder.HasBaseType(entityBuilder.Metadata, ConfigurationSource.Convention); - Assert.Equal(CoreStrings.DerivedEntityTypeKey(typeof(SpecialOrder).FullName), + Assert.Equal(CoreStrings.DerivedEntityTypeKey(typeof(SpecialOrder).FullName, typeof(Order).FullName), Assert.Throws(() => derivedEntityBuilder.PrimaryKey(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, ConfigurationSource.DataAnnotation)).Message); } diff --git a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs index 0cfcf9f850c..348bdc94dc9 100644 --- a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs +++ b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs @@ -861,6 +861,8 @@ private class EntityWithNoValidNavigations { public int Id { get; set; } + public object Object { get; set; } + public static OneToManyDependent Static { get; set; } public OneToManyDependent WriteOnly