使用sqlsugar通过主键查询报Only one primary key异常

在使用一款开源的ORM,sqlsugar,遇到一个问题,sqlsugar的介绍,就不介绍了。http://www.codeisbug.com/Doc/8/1121这是文档。https://github.com/sunkaixuan/SqlSugar 这是git地址

根据主键查询:

var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
/*
生成SQL: SELECT [ID],[Name] FROM [Student] WHERE [ID] = @param;
@param 值为 2
*/

在实体中,主键也打上对应的标签了

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

但是还是会爆这个异常“Only one primary key”

其实,在官方文档上,已经介绍过了:

SqlSugarClient db = new SqlSugarClient(
    new ConnectionConfig()
    {
        ConnectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest",
        DbType = DbType.SqlServer,//设置数据库类型
        IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放
        InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
    });
InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
InitKeyType有两个值:
public enum InitKeyType
    {
        SystemTable = 0,
        Attribute = 1
    }
原文地址:https://www.cnblogs.com/taotaozhuanyong/p/12674698.html