如何从json struct批量更新dapper?

时间:2016-12-08 05:58:55

标签: c# arrays json dapper bulkupdate

我在JSON结构中的数据就像这样

{
  "Imei": 356980051541947,
  "sendIds": [
    {
      "Id": 13014
    },
    {
      "Id": 13190
    },
    {
      "Id": 13419
    },
    {
      "Id": 13422
    }
  ],
  "ApplicationVersion": 68,
  "GoogleId": "asdsadazxcjkh218",
  "ImagesVersion": "123:1"
}

我的课程是:

public class PostData
{
    public int ApplicationVersion;
    public long Imei;
    public string GoogleId;
    public string FromDate;
    public string ToDate;
    public string ImagesVersion;
    public ItemId[] SendIds;
}

public class ItemId
{
    public int Id;
}

C#代码dapper update:

const string sql = "UPDATE dbo.SentMessage SET IsDelivered=1 WHERE SendID=@Id";
dapperConn.Execute(sql, postData.SendIds);

但执行

时会发生以下错误
  

必须声明标量变量\“@ Id \

请帮帮我。

1 个答案:

答案 0 :(得分:2)

发生此异常是因为您的类中的变量是Field而不是Property。因此,您必须将其更改为以下代码:

public class PostData
{
    public int ApplicationVersion { get; set; };
    public long Imei { get; set; };
    public string GoogleId { get; set; };
    public string FromDate { get; set; };
    public string ToDate { get; set; };
    public string ImagesVersion { get; set; };
    public ItemId[] SendIds { get; set; };
}

public class ItemId
{
    public int Id { get; set; };
}
相关问题