.N .NET Landscape

EFCore JSON value converter

Inactive Data Access
github.com/Innofactor/EfCoreJsonValueConverter

JSON ValueConverter for EF Core 3.0+

⚠ No commits for more than 2 years. Consider an actively maintained alternative from the same subcategory.

efcorejson
GitHub stars
97
Forks
17
Open issues
9
NuGet downloads
8,216,169
latest 6.0.0
License
LGPL-3.0
Language
C#
Last push
3 years ago
31 Aug 2023
Created
4 Jun 2018

JSON value converter for Entity Framework Core 3.0+

Publish NuGet

Serializes object properties in database as JSON blobs using Entity Framework Core value converters.

Usage example

Installing:

PM> Install-Package Innofactor.EfCoreJsonValueConverter

Annotate model properties with the JsonField attribute:

public class Customer {
  [JsonField]
  public Address Address { get; set; }
}

public class Address {
  // ...
}

This will persist Address property in database as JSON.

For DbContext:

  protected override void OnModelCreating(ModelBuilder builder) {

    builder.Entity<Customer>();
    builder.AddJsonFields();        
    
  }

Alternatively, individual fields can be mapped with the HasJsonValueConversion method:

  protected override void OnModelCreating(ModelBuilder builder) {

    builder.Entity<Customer>()
      .Property(m => m.Address)
      .HasJsonValueConversion();
    
  }

Note on performance

EF Core requires that tracked objects implement deep cloning and comparison. This library includes default fallback implementations for cloning and comparing, but for large objects that default implementation may be inefficient. To improve performance, it is recommended to manually implement ICloneable and IEquatable interfaces for complex JSON serialized objects. This library will then make use of those interfaces.

public class Address : ICloneable, IEquatable<Address> {
  // ...
}