0

I just face wall trying to create my.net API. I'm trying to Serialize data from db view into JSON. I can't make it to the below form.

  { name : "Name",
       someObject : {
                    name : "Name2"}

Could I can serialize it from single db view to that form? Or if no, how I can relate models and context created with dotnet ef dbcontext scaffold

Hope You can help me ❤

  • 3
    try `Newtonsoft.json` then `string DataPack = JsonConvert.SerializeObject(Data, Formatting.None);` – Mohammad Farahi May 26 '22 at 18:09
  • 2
    What does your object look like? The above is not valid json, by the way. – PMF May 26 '22 at 18:12
  • @PMF, Should looks like this: "Products" : [ {"productID" : "someID", "stockLevels" : [ {"warehouseID" : "someID", "availableStock" : someNumber}, {"warehouseID" : "someID", "availableStock" : someNumber} ]}], "companyId": "someID"} – Amator Szklanek May 26 '22 at 18:24
  • @PMF I don't have anything to show as an object. The case is that I'm not sure how I can model a single view into the needed form. DId its possible by serializing it or did I should create more views (single object- single view) and then create a class that will have these objects as properties. I already tried both but without positive results. – Amator Szklanek May 26 '22 at 18:34

0 Answers0