I have a problem during inserting data from a mobile app into an azure database.
My table in the database is defined like that:
This line couse an error:
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,
});
Error message:
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code Additional information: Cannot insert if the id member is already set. If there is a handler for this exception, the program may be safely continued.
And here is a definition of a User class:
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; }
}
我遇到了类似的问题,在我的情况下,在调试过程中,我发现我正在插入具有相同唯一标识符的条目,您可以尝试这个方向,并在插入之前检查是否重复。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.