@@ -4362,7 +4362,9 @@ public virtual void Owned_types_mapped_to_json_are_stored_in_snapshot()
43624362
43634363 b1.ToTable("EntityWithOneProperty", "DefaultSchema");
43644364
4365- b1.ToJson("EntityWithTwoProperties");
4365+ b1
4366+ .ToJson("EntityWithTwoProperties")
4367+ .HasColumnType("nvarchar(max)");
43664368
43674369 b1.WithOwner("EntityWithOneProperty")
43684370 .HasForeignKey("EntityWithOnePropertyId");
@@ -4437,6 +4439,7 @@ public virtual void Owned_types_mapped_to_json_are_stored_in_snapshot()
44374439
44384440 Assert . Equal ( nameof ( EntityWithOneProperty ) , ownedType1 . GetTableName ( ) ) ;
44394441 Assert . Equal ( "EntityWithTwoProperties" , ownedType1 . GetContainerColumnName ( ) ) ;
4442+ Assert . Equal ( "nvarchar(max)" , ownedType1 . GetContainerColumnType ( ) ) ;
44404443
44414444 var ownership2 = ownedType1 . FindNavigation ( nameof ( EntityWithStringKey ) ) . ForeignKey ;
44424445 Assert . Equal ( "EntityWithTwoPropertiesEntityWithOnePropertyId" , ownership2 . Properties [ 0 ] . Name ) ;
@@ -4473,6 +4476,83 @@ public virtual void Owned_types_mapped_to_json_are_stored_in_snapshot()
44734476 Assert . Equal ( "Name" , ownedProperties3 [ 3 ] . Name ) ;
44744477 } ) ;
44754478
4479+ [ ConditionalFact ]
4480+ public virtual void Owned_types_mapped_to_json_with_explicit_column_type_are_stored_in_snapshot ( )
4481+ => Test (
4482+ builder =>
4483+ {
4484+ builder . Entity < EntityWithOneProperty > ( b =>
4485+ {
4486+ b . HasKey ( x => x . Id ) . HasName ( "PK_Custom" ) ;
4487+
4488+ b . OwnsOne (
4489+ x => x . EntityWithTwoProperties , bb =>
4490+ {
4491+ bb . ToJson ( ) . HasColumnType ( "json" ) ;
4492+ bb . Ignore ( x => x . Id ) ;
4493+ bb . Property ( x => x . AlternateId ) . HasJsonPropertyName ( "NotKey" ) ;
4494+ bb . WithOwner ( e => e . EntityWithOneProperty ) ;
4495+ } ) ;
4496+ } ) ;
4497+ } ,
4498+ AddBoilerPlate (
4499+ GetHeading ( )
4500+ + """
4501+ modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithOneProperty", b =>
4502+ {
4503+ b.Property<int>("Id")
4504+ .ValueGeneratedOnAdd()
4505+ .HasColumnType("int");
4506+
4507+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
4508+
4509+ b.HasKey("Id")
4510+ .HasName("PK_Custom");
4511+
4512+ b.ToTable("EntityWithOneProperty", "DefaultSchema");
4513+ });
4514+
4515+ modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithOneProperty", b =>
4516+ {
4517+ b.OwnsOne("Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithTwoProperties", "EntityWithTwoProperties", b1 =>
4518+ {
4519+ b1.Property<int>("EntityWithOnePropertyId")
4520+ .HasColumnType("int");
4521+
4522+ b1.Property<int>("AlternateId")
4523+ .HasColumnType("int")
4524+ .HasAnnotation("Relational:JsonPropertyName", "NotKey");
4525+
4526+ b1.HasKey("EntityWithOnePropertyId");
4527+
4528+ b1.ToTable("EntityWithOneProperty", "DefaultSchema");
4529+
4530+ b1
4531+ .ToJson("EntityWithTwoProperties")
4532+ .HasColumnType("json");
4533+
4534+ b1.WithOwner("EntityWithOneProperty")
4535+ .HasForeignKey("EntityWithOnePropertyId");
4536+
4537+ b1.Navigation("EntityWithOneProperty");
4538+ });
4539+
4540+ b.Navigation("EntityWithTwoProperties");
4541+ });
4542+ """ , usingSystem : false ) ,
4543+ o =>
4544+ {
4545+ var entityWithOneProperty = o . FindEntityType ( typeof ( EntityWithOneProperty ) ) ;
4546+ Assert . Equal ( "PK_Custom" , entityWithOneProperty . GetKeys ( ) . Single ( ) . GetName ( ) ) ;
4547+
4548+ var ownership1 = entityWithOneProperty . FindNavigation ( nameof ( EntityWithOneProperty . EntityWithTwoProperties ) )
4549+ . ForeignKey ;
4550+ var ownedType1 = ownership1 . DeclaringEntityType ;
4551+ Assert . Equal ( nameof ( EntityWithOneProperty ) , ownedType1 . GetTableName ( ) ) ;
4552+ Assert . Equal ( "EntityWithTwoProperties" , ownedType1 . GetContainerColumnName ( ) ) ;
4553+ Assert . Equal ( "json" , ownedType1 . GetContainerColumnType ( ) ) ;
4554+ } ) ;
4555+
44764556 private class Order
44774557 {
44784558 public int Id { get ; set ; }
0 commit comments