Skip to content

Commit

Permalink
Cosmos: Don't map collections as owned types
Browse files Browse the repository at this point in the history
Reenable test for 24684

Fixes #25749
Fixes #24684
  • Loading branch information
AndriySvyryd committed Sep 1, 2021
1 parent b820df4 commit 09bef5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ 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.GetInterface("IEnumerable`1") == null;
}
}
Original file line number Diff line number Diff line change
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

0 comments on commit 09bef5a

Please sign in to comment.