@@ -62,7 +62,7 @@ public static class RelationalEntityTypeExtensions
62
62
63
63
var ownership = entityType . FindOwnership ( ) ;
64
64
if ( ownership != null
65
- && ownership . IsUnique )
65
+ && ( ownership . IsUnique || entityType . IsMappedToJson ( ) ) )
66
66
{
67
67
return ownership . PrincipalEntityType . GetTableName ( ) ;
68
68
}
@@ -316,7 +316,7 @@ public static IEnumerable<ITableMapping> GetTableMappings(this IEntityType entit
316
316
317
317
var ownership = entityType . FindOwnership ( ) ;
318
318
return ownership != null
319
- && ownership . IsUnique
319
+ && ( ownership . IsUnique || entityType . IsMappedToJson ( ) )
320
320
? ownership . PrincipalEntityType . GetViewName ( )
321
321
: null ;
322
322
}
@@ -1385,7 +1385,7 @@ public static IEnumerable<IReadOnlyForeignKey> FindRowInternalForeignKeys(
1385
1385
StoreObjectIdentifier storeObject )
1386
1386
{
1387
1387
var primaryKey = entityType . FindPrimaryKey ( ) ;
1388
- if ( primaryKey == null )
1388
+ if ( primaryKey == null || entityType . IsMappedToJson ( ) )
1389
1389
{
1390
1390
yield break ;
1391
1391
}
@@ -1855,4 +1855,96 @@ public static IEnumerable<ITrigger> GetDeclaredTriggers(this IEntityType entityT
1855
1855
=> Trigger . GetDeclaredTriggers ( entityType ) . Cast < ITrigger > ( ) ;
1856
1856
1857
1857
#endregion Trigger
1858
+
1859
+ #region Json
1860
+
1861
+ /// <summary>
1862
+ /// Gets a value indicating whether the specified entity is mapped to a JSON column.
1863
+ /// </summary>
1864
+ /// <param name="entityType">The entity type.</param>
1865
+ /// <returns>A value indicating whether the associated entity type is mapped to a JSON column.</returns>
1866
+ public static bool IsMappedToJson ( this IReadOnlyEntityType entityType )
1867
+ => ! string . IsNullOrEmpty ( entityType . GetJsonColumnName ( ) ) ;
1868
+
1869
+ /// <summary>
1870
+ /// Sets the name of the JSON column to which the entity type is mapped.
1871
+ /// </summary>
1872
+ /// <param name="entityType">The entity type to set the JSON column name for.</param>
1873
+ /// <param name="columnName">The name to set.</param>
1874
+ public static void SetJsonColumnName ( this IMutableEntityType entityType , string ? columnName )
1875
+ => entityType . SetOrRemoveAnnotation ( RelationalAnnotationNames . JsonColumnName , columnName ) ;
1876
+
1877
+ /// <summary>
1878
+ /// Sets the name of the JSON column to which the entity type is mapped.
1879
+ /// </summary>
1880
+ /// <param name="entityType">The entity type to set the JSON column name for.</param>
1881
+ /// <param name="columnName">The name to set.</param>
1882
+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
1883
+ /// <returns>The configured value.</returns>
1884
+ public static string ? SetJsonColumnName (
1885
+ this IConventionEntityType entityType ,
1886
+ string ? columnName ,
1887
+ bool fromDataAnnotation = false )
1888
+ => ( string ? ) entityType . SetAnnotation ( RelationalAnnotationNames . JsonColumnName , columnName , fromDataAnnotation ) ? . Value ;
1889
+
1890
+ /// <summary>
1891
+ /// Gets the <see cref="ConfigurationSource" /> for the JSON column name.
1892
+ /// </summary>
1893
+ /// <param name="entityType">The entity type to set the JSON column name for.</param>
1894
+ /// <returns>The <see cref="ConfigurationSource" /> for the JSON column name.</returns>
1895
+ public static ConfigurationSource ? GetJsonColumnNameConfigurationSource ( this IConventionEntityType entityType )
1896
+ => entityType . FindAnnotation ( RelationalAnnotationNames . JsonColumnName )
1897
+ ? . GetConfigurationSource ( ) ;
1898
+
1899
+ /// <summary>
1900
+ /// Gets the JSON column name to which the entity type is mapped.
1901
+ /// </summary>
1902
+ /// <param name="entityType">The entity type to get the JSON column name for.</param>
1903
+ /// <returns>The JSON column name to which the entity type is mapped.</returns>
1904
+ public static string ? GetJsonColumnName ( this IReadOnlyEntityType entityType )
1905
+ => entityType . FindAnnotation ( RelationalAnnotationNames . JsonColumnName ) ? . Value is string jsonColumnName
1906
+ ? jsonColumnName
1907
+ : ( entityType . FindOwnership ( ) ? . PrincipalEntityType . GetJsonColumnName ( ) ) ;
1908
+
1909
+ /// <summary>
1910
+ /// Sets the type mapping for the JSON column to which the entity type is mapped.
1911
+ /// </summary>
1912
+ /// <param name="entityType">The entity type to set the JSON column type mapping for.</param>
1913
+ /// <param name="typeMapping">The type mapping to set.</param>
1914
+ public static void SetJsonColumnTypeMapping ( this IMutableEntityType entityType , RelationalTypeMapping typeMapping )
1915
+ => entityType . SetOrRemoveAnnotation ( RelationalAnnotationNames . JsonColumnTypeMapping , typeMapping ) ;
1916
+
1917
+ /// <summary>
1918
+ /// Sets the type mapping for the JSON column to which the entity type is mapped.
1919
+ /// </summary>
1920
+ /// <param name="entityType">The entity type to set the JSON column type mapping for.</param>
1921
+ /// <param name="typeMapping">The type mapping to set.</param>
1922
+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
1923
+ /// <returns>The configured value.</returns>
1924
+ public static RelationalTypeMapping ? SetJsonColumnTypeMapping (
1925
+ this IConventionEntityType entityType ,
1926
+ RelationalTypeMapping ? typeMapping ,
1927
+ bool fromDataAnnotation = false )
1928
+ => ( RelationalTypeMapping ? ) entityType . SetAnnotation ( RelationalAnnotationNames . JsonColumnTypeMapping , typeMapping , fromDataAnnotation ) ? . Value ;
1929
+
1930
+ /// <summary>
1931
+ /// Gets the <see cref="ConfigurationSource" /> for the JSON column type mapping.
1932
+ /// </summary>
1933
+ /// <param name="entityType">The entity type to set the JSON column type mapping for.</param>
1934
+ /// <returns>The <see cref="ConfigurationSource" /> for the JSON column type mapping.</returns>
1935
+ public static ConfigurationSource ? GetJsonColumnTypeMappingConfigurationSource ( this IConventionEntityType entityType )
1936
+ => entityType . FindAnnotation ( RelationalAnnotationNames . JsonColumnTypeMapping )
1937
+ ? . GetConfigurationSource ( ) ;
1938
+
1939
+ /// <summary>
1940
+ /// Gets the JSON column type mapping to which the entity type is mapped.
1941
+ /// </summary>
1942
+ /// <param name="entityType">The entity type to get the JSON column type mapping for.</param>
1943
+ /// <returns>The JSON column type mapping to which the entity type is mapped.</returns>
1944
+ public static RelationalTypeMapping ? GetJsonColumnTypeMapping ( this IReadOnlyEntityType entityType )
1945
+ => entityType . FindAnnotation ( RelationalAnnotationNames . JsonColumnTypeMapping ) ? . Value is RelationalTypeMapping jsonColumnTypeMapping
1946
+ ? jsonColumnTypeMapping
1947
+ : ( entityType . FindOwnership ( ) ? . PrincipalEntityType . GetJsonColumnTypeMapping ( ) ) ;
1948
+
1949
+ #endregion
1858
1950
}
0 commit comments