C# 使用实体框架核心C反序列化JSON#

C# 使用实体框架核心C反序列化JSON#,c#,json,entity-framework,entity-framework-core,C#,Json,Entity Framework,Entity Framework Core,基本上,我希望获得(直接反序列化为对象)低于JSON的“rows”属性下的数据 我需要创建哪些包装器类以便直接使用 JsonConvert.DeserializeObject(消息)获取此数据的“行”:[[19.545363672276512,“JapanUnifia试验”,20180331,“USD”],[173.41979241290323,“RVIIOT-Trial”,20180331,“USD”],[20.359416562625452,“VSTSHOL-1595322048000”,2

基本上,我希望获得(直接反序列化为对象)低于JSON的“rows”属性下的数据

我需要创建哪些包装器类以便直接使用 JsonConvert.DeserializeObject(消息)获取此数据的“行”:[[19.545363672276512,“JapanUnifia试验”,20180331,“USD”],[173.41979241290323,“RVIIOT-Trial”,20180331,“USD”],[20.359416562625452,“VSTSHOL-1595322048000”,20180331,“USD”]作为一些对象的数组,可以使用EF核心保存在数据库中

{
  "id": "providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
  "name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
  "type": "microsoft.costmanagement/Query",
  "properties": {
    "nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query?api-version=2019-10-01&$skiptoken=AQAAAA%3D%3D",
    "columns": [
      {
        "name": "PreTaxCost",
        "type": "Number"
      },
      {
        "name": "ResourceGroup",
        "type": "String"
      },
      {
        "name": "UsageDate",
        "type": "Number"
      },
      {
        "name": "Currency",
        "type": "String"
      }
    ],
    "rows": [
      [
        19.545363672276512,
        "JapanUnifia-Trial",
        20180331,
        "USD"
      ],
      [
        173.41979241290323,
        "RVIIOT-TRIAL",
        20180331,
        "USD"
      ],
      [
        20.359416562625452,
        "VSTSHOL-1595322048000",
        20180331,
        "USD"
      ]
    ]
  }
}

此示例json取自

,以下是获取
属性的类:

public class Properties
{
    public List<List<object>> rows { get; set; }
}

public class Root
{
    public Properties properties { get; set; }
}
要在数据库中使用此数据,请使用模型类:

public class dbModel
{
    public double propertyName { get; set; }
    // Add other properties

    //With the name of db model and view model being valid table names
    //the properties being of the same data types as values.rows
}
public class dbViewModel
{
    public IEnumerable<dbModel> dbModels { get; set; }

    //Use this class to Enumerate through the rows
}
和视图模型类:

public class dbModel
{
    public double propertyName { get; set; }
    // Add other properties

    //With the name of db model and view model being valid table names
    //the properties being of the same data types as values.rows
}
public class dbViewModel
{
    public IEnumerable<dbModel> dbModels { get; set; }

    //Use this class to Enumerate through the rows
}
公共类dbViewModel
{
公共IEnumerable数据库模型{get;set;}
//使用此类枚举所有行
}

以下是获取
属性的类:

public class Properties
{
    public List<List<object>> rows { get; set; }
}

public class Root
{
    public Properties properties { get; set; }
}
要在数据库中使用此数据,请使用模型类:

public class dbModel
{
    public double propertyName { get; set; }
    // Add other properties

    //With the name of db model and view model being valid table names
    //the properties being of the same data types as values.rows
}
public class dbViewModel
{
    public IEnumerable<dbModel> dbModels { get; set; }

    //Use this class to Enumerate through the rows
}
和视图模型类:

public class dbModel
{
    public double propertyName { get; set; }
    // Add other properties

    //With the name of db model and view model being valid table names
    //the properties being of the same data types as values.rows
}
public class dbViewModel
{
    public IEnumerable<dbModel> dbModels { get; set; }

    //Use this class to Enumerate through the rows
}
公共类dbViewModel
{
公共IEnumerable数据库模型{get;set;}
//使用此类枚举所有行
}

将其反序列化为列表行后,我必须在每个数组元素[173.41979241290323,“RVIIOT-TRIAL”,20180331,“USD”]上迭代它,并用这4个值创建一个对象,它表示我的数据模型和一个DB表。当使用JsonConvert.DeserializeObject(message.properties.rows)时,是否有一种直接的方法使其自身反序列化;我现在看到了我答案中的缺陷。这完全可以在没有ViewModel的情况下完成。但这是我会考虑并尝试更新我的答案的。无论如何,谢谢你们的支持和时间。你的想法行得通,我现在就在使用它。很高兴能提供帮助,在这种情况下,我可能不会使用视图模型,但它是可选的,只需循环遍历
,将每个值初始化为db模型类的一个实例,并将其添加到DBA中。在将其反序列化为列表行后,我必须对每个数组元素进行迭代[173.41979241290323,“RVIIOT-TRIAL”,20180331,“USD”]并用这4个值创建一个对象,它代表我的数据模型和数据库中的一个表。在使用JsonConvert.DeserializeObject(消息)时,难道没有直接的方法使其自身反序列化吗.properties.rows;我现在看到了我的答案中的缺陷。在没有ViewModel的情况下肯定可以做到。但这是我会考虑并尝试更新我的答案的。无论如何,感谢您的支持和时间。您的想法很有效,我现在正在使用它。很高兴能提供帮助,在这种情况下,我可能不会使用ViewModel,但它是可选的,并且只需循环遍历
,将每个值初始化为db模型类的实例并添加到db中