在使用一款開源的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 }