【发布时间】:2021-04-07 13:43:15
【问题描述】:
我尝试使用以下代码将数据插入 Azure SQL 数据库:
Users user = new Users()
{
username = txtUsername.Text,
userPassword = txtPassword.Text
};
await App.client.GetTable<Users>().InsertAsync(user);
当我运行代码时,我得到了这个错误:
InvalidOperationExecution:在 Model.Users 类型上找不到 id 成员
所以我检查了我的 C# 模型类:
public class Users
{
[JsonProperty(PropertyName = "user_id")]
public int user_id { get; set; }
public string username { get; set; }
public string userPassword { get; set; }
}
我尝试将 json 属性从 user_id 更改为 id,如下所示:
public class Users
{
[JsonProperty(PropertyName = "id")]
public int user_id { get; set; }
public string username { get; set; }
public string userPassword { get; set; }
}
当我再次运行它时,我仍然得到一个错误:
InvalidOperationExecution:在 Model.Users 类型上找不到 id 成员
我该怎么办?我一开始已经提供了user_id,但它显示错误,我哪里出错了?
这是我的数据库
Create table Users
(
user_id int primary key identity(1,1),
username varchar(30) not null,
user varchar(30) not null,
)
【问题讨论】:
-
请分享您声明哪一列是主键的代码。
标签: c# azure xamarin azure-sql-database