XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions
2.0.4
See the version list below for details.
dotnet add package XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions --version 2.0.4
NuGet\Install-Package XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions -Version 2.0.4
<PackageReference Include="XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions" Version="2.0.4" />
paket add XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions --version 2.0.4
#r "nuget: XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions, 2.0.4"
// Install XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions as a Cake Addin #addin nuget:?package=XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions&version=2.0.4 // Install XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions as a Cake Tool #tool nuget:?package=XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions&version=2.0.4
XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions
An Entity Framework Core plugin that adds support for JsonSerializerOptions
to the Npgsql provider. You could use it to influence the property naming policy, or to use JSON source generation. These features are planned for Entity Framework Core 8.0, but until then...
Usage
Call the extension method to add the plugin to your
DbContext
.protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder .UseNpgsql("Host=localhost") .UseNpgsqlJsonSerializerOptions(); }
Call
UseJsonSerializerOptions
to configureJsonSerializerOptions
for a specific property.protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>(entity => { entity.Property(x => x.MyJsonProperty) .HasColumnType("jsonb") .UseJsonSerializerOptions(new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }); }); }
Options
Default Serializer Options
To apply default JsonSerializerOptions
to all json
and jsonb
columns, pass the default instance to the options builder:
Note: When configuring the default serializer options, pass the same instance every time your configuration callback is invoked. Otherwise, Entity Framework will detect the options have changed and construct a new
IServiceProvider
for everyDbContext
!
private static readonly JsonSerializerOptions defaultOptions
= new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseNpgsql("Host=localhost")
.UseNpgsqlJsonSerializerOptions(defaultOptions);
}
JsonSerializerValueComparer<T>
By default, the plugin configures affected entity properties to use JsonSerializerValueComparer<T>
for value equality comparison, which serializes each value to JSON and compares the resulting strings. If you prefer the default value comparer's semantics for your value type(s), or if you just don't want the additional serialization overhead, you can disable it:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseNpgsql("Host=localhost")
.UseNpgsqlJsonSerializerOptions(useJsonSerializerValueComparer: false);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.0)
- Npgsql (>= 7.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.