Skip to content
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

Cosmos: Don't map collections as owned types #25827

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public CosmosRelationshipDiscoveryConvention(ProviderConventionSetBuilderDepende
/// <param name="model"> The model. </param>
/// <returns> <see langword="true"/> if the given entity type should be owned. </returns>
public static bool ShouldBeOwnedType(Type targetType, IConventionModel model)
=> !targetType.IsGenericType || targetType.GetGenericTypeDefinition() != typeof(List<>);
=> !targetType.IsGenericType
|| targetType == typeof(Dictionary<string, object>)
|| targetType.GetInterface(typeof(IEnumerable<>).Name) == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override void Object_to_string_conversion()
base.Object_to_string_conversion();

AssertSql(
@"SELECT c[""TestSignedByte""], c[""TestByte""], c[""TestInt16""], c[""TestUnsignedInt16""], c[""TestInt32""], c[""TestUnsignedInt32""], c[""TestInt64""], c[""TestUnsignedInt64""], c[""TestSingle""], c[""TestDouble""], c[""TestDecimal""], c[""TestCharacter""], c[""TestDateTime""], c, c[""TestTimeSpan""]
@"SELECT c[""TestSignedByte""], c[""TestByte""], c[""TestInt16""], c[""TestUnsignedInt16""], c[""TestInt32""], c[""TestUnsignedInt32""], c[""TestInt64""], c[""TestUnsignedInt64""], c[""TestSingle""], c[""TestDouble""], c[""TestDecimal""], c[""TestCharacter""], c[""TestDateTime""], c[""TestDateTimeOffset""], c[""TestTimeSpan""]
FROM root c
WHERE ((c[""Discriminator""] = ""BuiltInDataTypes"") AND (c[""Id""] = 13))");
}
Expand Down Expand Up @@ -117,10 +117,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
shadowJObject.SetConfigurationSource(ConfigurationSource.Convention);
var nullableShadowJObject = (Property)modelBuilder.Entity<BuiltInNullableDataTypesShadow>().Property("__jObject").Metadata;
nullableShadowJObject.SetConfigurationSource(ConfigurationSource.Convention);

// Issue #24684
modelBuilder.Entity<BuiltInDataTypes>().Ignore(e => e.TestDateTimeOffset);
modelBuilder.Entity<BuiltInDataTypesShadow>().Ignore("TestDateTimeOffset");
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,24 @@ protected class ThreeDee
public int[,,] Three { get; set; }
}

[ConditionalFact]
protected virtual void Throws_for_int_keyed_dictionary()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<IntDict>();

Assert.Equal(
CoreStrings.EntityRequiresKey(typeof(Dictionary<int, string>).ShortDisplayName()),
Assert.Throws<InvalidOperationException>(() => modelBuilder.FinalizeModel()).Message);
}

protected class IntDict
{
public int Id { get; set; }
public Dictionary<int, string> Notes { get; set; }
}

[ConditionalFact]
public virtual void Can_set_unicode_for_properties()
{
Expand Down