Skip to content

Commit 4339f98

Browse files
committed
Block EF7 JSON usage
Closes npgsql#2452
1 parent aea5d05 commit 4339f98

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

src/EFCore.PG/Infrastructure/Internal/NpgsqlModelValidator.cs

+14
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ static void ValidateSproc(IStoredProcedure sproc, IDiagnosticsLogger<DbLoggerCat
193193
}
194194
}
195195

196+
/// <inheritdoc />
197+
protected override void ValidateJsonEntities(
198+
IModel model,
199+
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
200+
{
201+
foreach (var entityType in model.GetEntityTypes())
202+
{
203+
if (entityType.IsMappedToJson())
204+
{
205+
throw new InvalidOperationException(NpgsqlStrings.Ef7JsonMappingNotSupported);
206+
}
207+
}
208+
}
209+
196210
/// <inheritdoc />
197211
protected override void ValidateCompatible(
198212
IProperty property,

src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
2+
13
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal;
24

35
/// <summary>
@@ -127,11 +129,11 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
127129
.ToArray());
128130
}
129131

130-
// Model validation ensures that these facets are the same on all mapped properties
131-
var property = column.PropertyMappings.First().Property;
132-
133-
if (property.GetCompressionMethod() is { } compressionMethod)
132+
// JSON columns have no property mappings so all annotations that rely on property mappings should be skipped for them
133+
if (column is not JsonColumn
134+
&& column.PropertyMappings.FirstOrDefault()?.Property.GetCompressionMethod() is { } compressionMethod)
134135
{
136+
// Model validation ensures that these facets are the same on all mapped properties
135137
yield return new Annotation(NpgsqlAnnotationNames.CompressionMethod, compressionMethod);
136138
}
137139
}

src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EFCore.PG/Properties/NpgsqlStrings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<data name="DuplicateIndexIncludedMismatch" xml:space="preserve">
133133
<value>The indexes {index1} on '{entityType1}' and {index2} on '{entityType2}' are both mapped to '{table}.{indexName}', but have different included columns: {includedColumns1} and {includedColumns2}.</value>
134134
</data>
135+
<data name="Ef7JsonMappingNotSupported" xml:space="preserve">
136+
<value>The EF Core 7.0 JSON support isn't currently supported by the Npgsql provider. To map to JSON, see https://www.npgsql.org/efcore/mapping/json.html.</value>
137+
</data>
135138
<data name="FreeTextFunctionOnClient" xml:space="preserve">
136139
<value>The 'FreeText' method is not supported because the query has switched to client-evaluation. Inspect the log to determine which query expressions are triggering client-evaluation.</value>
137140
</data>

src/EFCore.PG/Update/Internal/NpgsqlModificationCommand.cs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public override void PropagateResults(RelationalDataReader relationalReader)
6464

6565
case IColumn:
6666
case IStoreStoredProcedureParameter:
67+
case null when columnModification.JsonPath is not null:
6768
continue;
6869

6970
default:

0 commit comments

Comments
 (0)