JsonProperty.EFCore 2.6.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonProperty.EFCore --version 2.6.2                
NuGet\Install-Package JsonProperty.EFCore -Version 2.6.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonProperty.EFCore" Version="2.6.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonProperty.EFCore --version 2.6.2                
#r "nuget: JsonProperty.EFCore, 2.6.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonProperty.EFCore as a Cake Addin
#addin nuget:?package=JsonProperty.EFCore&version=2.6.2

// Install JsonProperty.EFCore as a Cake Tool
#tool nuget:?package=JsonProperty.EFCore&version=2.6.2                

JsonProperty.EFCore

Version

About

This project allows you to use JSON fields in EF Core without setting up Fluent API

Id Name Price Params
1 Phone 500 {"Camera":13.5,"OS":"Android 11","Screen":"1080x900","Storage":32}
2 Car 100000 {"MaxSpeed":300,"Engine capacity":6,"ElectroCar":false}
3 Bag 400 {"Voliume":5,"Color":"Red"}

Instruction

Here are few steps how to use JsonProperty.EFCore project:

  1. Connect the project and specify 'using'

    using JsonProperty.EFCore;
    
  2. Create entity model

    public class Product
    {
        [Key, Required]
        public int Id { get; set; }
        public string? Name { get; set; }
        public decimal? Price { get; set; }
    }
    

    Or

    public class Note
    {
        [Key, Required]
        public int Id { get; set; }
        public string? Header { get; set; }
    }
    
  3. Create a JSON collection item class if necessary

    public class TodoItem
    {
        public string? Text { get; set; }
        public bool? CompleteStatus { get; set; }
    }
    
  4. Add JSON field property of type JsonEntity, JsonList or JsonDictionary to your entity model

    You can use the basic type like JsonEntity or JsonDictionary which uses elements of type object

    public class Product
    {
        [Key, Required]
        public int Id { get; set; }
        public string? Name { get; set; }
        public decimal? Price { get; set; }
    
        public JsonDictionary Parameters { get; set; } = new();
    }
    

    Or add property of generic type like JsonEnumerable<T> or JsonDictionary<TKey, TValue> with custom element type

    public class Note
    {
        [Key, Required]
        public int Id { get; set; }
        public string? Header { get; set; }
    
        public JsonEnumerable<TodoItem> Todos { get; set; } = new();
    }
    
  5. Usage example:

    Here is example for JsonDictionary

    Product product = new() {Name="Phone",Price=500.95m,Amount=21,Parameters={
        VirtualDictionary = new Dictionary<string,object>() {
            {"Camera",13.5 },{"OS","Android" },{"Screen","1080x900"},{"Storage",32}
        }
    }};
    db.Goods.Add(product);
    db.SaveChanges();
    

    This will generate the following JSON data into the corresponding table string field:

    { "Camera": 13.5, "OS": "Android", "Screen": "1080x900", "Storage": 32 }
    

    And here is example for JsonEnumerable<T>

    Note note = db.Notes.FirstOrDefault();
    note.Todos.Edit(en => en.Append(new("MyTodoItemTitle")));
    

    And here is also the result in JSON:

    [ ... , { "Text": "MyTodoItemTitle", "CompleteStatus": false }]
    
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.7.0 9,589 7/16/2023
2.6.5 165 7/15/2023
2.6.4 151 7/15/2023
2.6.3 152 7/13/2023
2.6.2 158 7/13/2023
2.5.2 167 7/12/2023
2.5.1 175 7/12/2023
2.5.0 187 7/12/2023