SqlSugarException: Please set SqlSugarClent Parameter ConnectionConfig.InitKeyType=InitKeyType.Attri
时间: 2024-04-29 09:20:54 浏览: 169
ISO 28591:2017 Sequential sampling plans for inspection by attri
This exception is thrown when using SqlSugar, a lightweight ORM library for .NET, and attempting to execute a query without setting the InitKeyType parameter of the ConnectionConfig object to InitKeyType.Attri.
By default, SqlSugar uses InitKeyType.SystemTable to determine the primary keys of tables in the database. However, if the primary keys are defined using attributes in the model classes, InitKeyType.Attri must be used instead.
To resolve this exception, set the InitKeyType parameter of the ConnectionConfig object to InitKeyType.Attri before executing any queries. For example:
```
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "your connection string",
DbType = DbType.SqlServer,
InitKeyType = InitKeyType.Attri // set InitKeyType to Attri
});
var result = db.Queryable<MyModel>().ToList();
```
阅读全文