0

I generate object with EF and SQL to LINQ, and have complexs types which is returned from stored procedure. Now want to serialize those objects to nested JSON file, by using Newtonsoft json librarys.

The problem which have is that all serialized JSON files are flatten (cause returned result from procedures are all rows), now what want to ask is -

What tehnics to use to get nice structured (nested) JSON automatically (I need to serialize lot of procedure)?

Is there way to configure EF or SQL to LINQ to have functionality like polymorphic associations (like this, but that's old)

Example:

[{"key":value,"key":value,"key":value...}] --> generated JSON

Want get to look like:

{
  "key": value,
  "key": value,
  .
  .
  .
  },
   "table1":     <------ structured like this
  {
    "key": value
    "key": value
  },
  "table2": 
  {
    "key": value
    "key": value
  }
}
Ivan Pericic
  • 522
  • 1
  • 8
  • 24
  • 1
    Sure. Load up your result set into an object with `key` and `value` properties... or write a [custom JsonConverter](https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm) – Sam Axe Aug 31 '17 at 08:41
  • @SamAxe thnx ... if i have many procedures (object in c#) which is generated from SQL to LINQ - should i make all those object subclasses from jsonconvertor class? (Cause I see that all object which use jsonconvertor must be derived from it). Can i make one custom object with all linq objects as properties and use those object to generate JSON? – Ivan Pericic Aug 31 '17 at 09:17
  • well after testing ... it's seems that is not possible (or much work) to get nested objects with JsonConverter - cause it get already flat filled object which than don't know how to nested. For that i should check for every procedure which columns belong to which table and after that serialize it. Also it is problem when have same column name in more tables how to treat it. – Ivan Pericic Aug 31 '17 at 10:00

0 Answers0