• 2019年5月9日

SqlSugar出错 “Only one primary key”

新代码调试出现“Only one primary key”错误,一时不知道咋解决。按照字面的意思是“只能有1个主键”,所以以为是数据库弄了多个主键!

最终发现问题出现在原来我没有代码中指定主键,解决办法就是在Id定义前面添加1条代码:

[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

例如:

[SugarTable("User")]
public class UserModel
{
    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
    public int Id{get;set;}
    public string UserName{get;set;}
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注