【问题标题】:Fail to InsertAsync() into azure database无法将 InsertAsync() 插入天蓝色数据库
【发布时间】:2013-06-22 11:27:20
【问题描述】:

我在将数据从移动应用程序插入 Azure 数据库时遇到问题。

我在数据库中的表是这样定义的:

这行会出错:

        await usersTable.InsertAsync(
            new User
            {
                FirstName = this.FirstNameTextBox.Text,
                LastName = this.LastNameTextBox.Text,
                DepartmentID = 0,
                LiveID = App.MobileService.CurrentUser.UserId,
                Level = 0,
                Pluses = 0,
                Minuses = 0,
            });

错误信息:

“System.ArgumentException”类型的异常发生在 mscorlib.dll 中,但未在用户代码中处理 附加信息:如果 id 成员已设置,则无法插入。 如果有这个异常的处理程序,程序可以安全地继续。

这里是一个用户类的定义:

class User
{
    [JsonProperty(PropertyName = "ID")]
    public string LiveID { get; set; }

    [JsonProperty(PropertyName = "FirstName")]
    public string FirstName { get; set; }

    [JsonProperty(PropertyName = "LastName")]
    public string LastName { get; set; }

    [JsonProperty(PropertyName = "DepartmentID")]
    public int DepartmentID { get; set; }

    [JsonProperty(PropertyName = "Level")]
    public int Level { get; set; }

    [JsonProperty(PropertyName = "Pluses")]
    public int Pluses { get; set; }

    [JsonProperty(PropertyName = "Minuses")]
    public int Minuses { get; set; }
}

【问题讨论】:

标签: c# mobile azure service azure-sql-database


【解决方案1】:

我遇到了类似的问题,在我的情况下,在调试过程中,我发现我正在插入一个具有相同唯一标识符的条目,你可以尝试这个方向,并在插入之前检查是否重复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 2017-01-17
    • 2012-04-13
    相关资源
    最近更新 更多