locked
Storing a attribute with JSON value in CosmosDB using Entity Framework Core 3 RRS feed

  • Question

  • I using EF Core Cosmos Provider in my API to consume my CosmosDB. Inside my container items in cosmos , I want a Attribute to store JSON value and also should be mapped to my models classes in EF core. Items in my cosmos container looks like this:

    {

        "id": "abcd",

        "Name": "name Value",

        "Discriminator": "EntityTest",

        "PartitionKey": "xyz",

        "Parameters": {

            "Parameter_1": "parameter value",

            "Parameter_2": "",

            "Parameter_3": "No"

        },

    }

    {

        "id": "tisd",

        "Name": "name Value",

        "Discriminator": "EntityTest",

        "PartitionKey": "xyz",

        "Parameters": {

            "Parameter_5": "parameterValue",

            "Parameter_6": ""

        },

    }

    As you can see that the fields inside the "Parameters" attribute are dynamic, how can I map this to a model class in EF core?

    For now I have implemented it using __jObject shadow property that allows us to store values as JObject's in our container, but on the official documentation site for __jObject, the have said and I quote :

    "The "__jObject" property is part of the EF Core infrastructure and should only be used as a last resort as it is likely to have different behavior in future releases."

    If you have any insights on what kind of changes I should expect in __jObject behavior in future releases, it will be really helpful. 

    Thanks



    Monday, August 17, 2020 9:30 AM

All replies