Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Column handling with unknown/dynamic structure #32043

Closed
mawi1512 opened this issue Oct 13, 2023 · 2 comments
Closed

JSON Column handling with unknown/dynamic structure #32043

mawi1512 opened this issue Oct 13, 2023 · 2 comments

Comments

@mawi1512
Copy link

Hello everyone,

I’m attempting to use the JSON columns feature in Entity Framework Core with a database where JSON data is stored as strings. The problem is that the structure of these JSON objects varies and is not known at compile time.

I’ve tried to handle this using dynamic, ExpandoObject, JsonObject, and Dictionary, but haven’t had any success.

Here’s a simplified version of my entity:

public partial class MyEntity
{
    public string Id { get; set; } = null!;
    public JsonObject Content { get; set; } = null!;
}

My goal is to create a web API that allows users to apply filters to the JSON content (similar to OData). Currently, I’m serializing/deserializing my JSON as a string, which doesn’t allow for server-side dynamic querying/filtering. This has to be done client-side, which isn’t very efficient.

So basically i want to do something like that (pseudo code):

var result = context.MyEntity
        .Where(entity=> entity.JsonObject[PathInsideJson] == filterValue)
        .ToList();

Is it somehow possible to query dynamic jsons? Should I resort to writing SQL queries? Can dynamic linq help? Any guidance or suggestions would be greatly appreciated.

Thank you for your help!


EF Core version: 8.0 RC1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 8.0 RC1
Operating system: Windows
IDE: Visual Studio 2022 17.8.0 Preview 2

@roji
Copy link
Member

roji commented Oct 13, 2023

Duplicate of #29825 and/or #28871.

EF doesn't yet support dynamic JSON mapping; it currently requires that the JSON document shape be known in advance, and modeled via a .NET POCO type. #29825 tracks allowing mapping dynamic JSON as a dictionary, whereas #28871 tracks doing so via the the System.Text.Json APIs (JsonDocument/JsonElement).

@mawi1512
Copy link
Author

Thanks for your fast response. I have set my votes :)

@mawi1512 mawi1512 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants