Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Jul 21, 2025

For both structural mapping (ToJson() on complex type/owned entity) and scalar collections.

Closes #36372

@roji roji requested a review from a team July 21, 2025 15:31
@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 21, 2025

Will this also apply to reverse engineering?

@roji roji marked this pull request as draft July 21, 2025 16:08
@roji
Copy link
Member Author

roji commented Jul 21, 2025

@ErikEJ this is specifically for ToJson(), i.e. mapping complex (or owned) types to the database - we can't reverse engineer that, since all we know is that there's a JSON column in the database and have no idea what .NET type should be mapped to it. When we see a json type in the database, we reverse-engineer that to a string property, since that's probably the best we can do - the user must then decide whether they want to change that to some ToJson() mapping, or to a primitive collection of ints, or whatever.

Does that make sense, or am I missing something?

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 21, 2025

@roji Makes sense, thanks

@roji roji marked this pull request as ready for review July 21, 2025 22:48
@roji roji enabled auto-merge (squash) July 21, 2025 22:49
}

[ConditionalFact]
public void Json_is_mapped_to_nvarchar_with_UseSqlServer_with_compatibility_level_170()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void Json_is_mapped_to_nvarchar_with_UseSqlServer_with_compatibility_level_170()
public void Json_is_mapped_to_json_type_with_UseSqlServer_with_compatibility_level_170()

@frankbuckley
Copy link

The docs state:

Starting with EF 9, it's recommended to use UseAzureSql and UseAzureSynapse to specify that you're connecting to Azure SQL or Azure Synapse Analytics specifically, and UseSqlServer to specify that you're connecting to on-premises SQL Server

This seems unclear about what to use with Azure SQL Managed Instance.

If Azure SQL Managed Instance is configured with SQL Server 2022 update policy, then JSON data type is not available.

Comment on lines +432 to +446
// => TryFindJsonCollectionMapping(
// info.CoreTypeMappingInfo, modelType, providerType, ref elementMapping, out var comparer, out var collectionReaderWriter)
// ? (RelationalTypeMapping)FindMapping(
// info.WithConverter(
// // Note that the converter info is only used temporarily here and never creates an instance.
// new ValueConverterInfo(modelType, typeof(string), _ => null!)))!
// .WithComposedConverter(
// (ValueConverter)Activator.CreateInstance(
// typeof(CollectionToJsonStringConverter<>).MakeGenericType(
// modelType.TryGetElementType(typeof(IEnumerable<>))!), collectionReaderWriter!)!,
// comparer,
// comparer,
// elementMapping,
// collectionReaderWriter)
// : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing in #36407

@roji roji merged commit 9f1670d into dotnet:main Jul 22, 2025
7 checks passed
@roji roji deleted the JsonType branch July 22, 2025 23:43
@roji
Copy link
Member Author

roji commented Jul 23, 2025

@frankbuckley yeah, the docs should be clearer on the different Azure SQL offerings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL Server: use new JSON type when the compatibility level is set to 170

4 participants