How do I use automapper to map a dataset with multiple tables

前端 未结 2 1523
执念已碎
执念已碎 2021-01-02 13:15

DISCLAIMER: this is a copy paste from an older stackoverflow post that isn\'t available anymore, but I have exaclty the same problem, so it seemed appropriate to rep

2条回答
  •  情书的邮戳
    2021-01-02 13:49

    I'm incredibly late to the party, but in case this helps someone else.

    What I did was serialize my dataset to a JSON string using Json.NET.

    var datasetSerialized = JsonConvert.SerializeObject(dataset, Formatting.Indented);
    

    View the json as a string whilst debugging in Visual Studio and copy this to your clipboard.

    Then in Visual Studio go to Edit -> Paste Special -> Paste JSON As Classes

    You will then have a POCO for each table with relationships.

    Finally, deserialize your JSON into the "RootObject" created when you pasted the JSON As Classes.

    var rootObj = JsonConvert.DeserializeObject(datasetSerialized);
    

提交回复
热议问题