@@ -286,12 +286,14 @@ private static void AddDefaultMappings(
286
286
includesDerivedTypes : entityType . GetDirectlyDerivedTypes ( ) . Any ( )
287
287
? ! isTpc && mappedType == entityType
288
288
: null ) ;
289
+
289
290
var containerColumnName = mappedType . GetContainerColumnName ( ) ;
291
+ var containerColumnType = mappedType . GetContainerColumnType ( ) ;
290
292
if ( ! string . IsNullOrEmpty ( containerColumnName ) )
291
293
{
292
294
CreateContainerColumn (
293
- defaultTable , containerColumnName , mappedType , relationalTypeMappingSource ,
294
- static ( c , t , m ) => new JsonColumnBase ( c , m . StoreType , t , m ) ) ;
295
+ defaultTable , containerColumnName , containerColumnType , mappedType , relationalTypeMappingSource ,
296
+ static ( colName , colType , table , mapping ) => new JsonColumnBase ( colName , colType ?? mapping . StoreType , table , mapping ) ) ;
295
297
}
296
298
else
297
299
{
@@ -492,11 +494,12 @@ private static void CreateTableMapping(
492
494
} ;
493
495
494
496
var containerColumnName = mappedType . GetContainerColumnName ( ) ;
497
+ var containerColumnType = mappedType . GetContainerColumnType ( ) ;
495
498
if ( ! string . IsNullOrEmpty ( containerColumnName ) )
496
499
{
497
500
CreateContainerColumn (
498
- table , containerColumnName , ( IEntityType ) mappedType , relationalTypeMappingSource ,
499
- static ( c , t , m ) => new JsonColumn ( c , m . StoreType , ( Table ) t , m ) ) ;
501
+ table , containerColumnName , containerColumnType , ( IEntityType ) mappedType , relationalTypeMappingSource ,
502
+ static ( colName , colType , table , mapping ) => new JsonColumn ( colName , colType ?? mapping . StoreType , ( Table ) table , mapping ) ) ;
500
503
}
501
504
else
502
505
{
@@ -567,18 +570,19 @@ private static void CreateTableMapping(
567
570
private static void CreateContainerColumn < TColumnMappingBase > (
568
571
TableBase tableBase ,
569
572
string containerColumnName ,
573
+ string ? containerColumnType ,
570
574
IEntityType mappedType ,
571
575
IRelationalTypeMappingSource relationalTypeMappingSource ,
572
- Func < string , TableBase , RelationalTypeMapping , ColumnBase < TColumnMappingBase > > createColumn )
576
+ Func < string , string ? , TableBase , RelationalTypeMapping , ColumnBase < TColumnMappingBase > > createColumn )
573
577
where TColumnMappingBase : class , IColumnMappingBase
574
578
{
575
579
var ownership = mappedType . GetForeignKeys ( ) . Single ( fk => fk . IsOwnership ) ;
576
580
if ( ! ownership . PrincipalEntityType . IsMappedToJson ( ) )
577
581
{
578
582
Check . DebugAssert ( tableBase . FindColumn ( containerColumnName ) == null , $ "Table does not have column '{ containerColumnName } '.") ;
579
583
580
- var jsonColumnTypeMapping = relationalTypeMappingSource . FindMapping ( typeof ( JsonElement ) , mappedType . Model ) ! ;
581
- var jsonColumn = createColumn ( containerColumnName , tableBase , jsonColumnTypeMapping ) ;
584
+ var jsonColumnTypeMapping = relationalTypeMappingSource . FindMapping ( typeof ( JsonElement ) , storeTypeName : containerColumnType ) ! ;
585
+ var jsonColumn = createColumn ( containerColumnName , containerColumnType , tableBase , jsonColumnTypeMapping ) ;
582
586
tableBase . Columns . Add ( containerColumnName , jsonColumn ) ;
583
587
jsonColumn . IsNullable = ! ownership . IsRequiredDependent || ! ownership . IsUnique ;
584
588
@@ -684,11 +688,12 @@ private static void CreateViewMapping(
684
688
} ;
685
689
686
690
var containerColumnName = mappedType . GetContainerColumnName ( ) ;
691
+ var containerColumnType = mappedType . GetContainerColumnType ( ) ;
687
692
if ( ! string . IsNullOrEmpty ( containerColumnName ) )
688
693
{
689
694
CreateContainerColumn (
690
- view , containerColumnName , mappedType , relationalTypeMappingSource ,
691
- static ( c , t , m ) => new JsonViewColumn ( c , m . StoreType , ( View ) t , m ) ) ;
695
+ view , containerColumnName , containerColumnType , mappedType , relationalTypeMappingSource ,
696
+ static ( colName , colType , table , mapping ) => new JsonViewColumn ( colName , colType ?? mapping . StoreType , ( View ) table , mapping ) ) ;
692
697
}
693
698
else
694
699
{
0 commit comments