我正在尝试 Dapper,偶然发现了这个异常:
System.InvalidOperationException: The ConnectionString property has not been initialized.
...
Run Code Online (Sandbox Code Playgroud)
这是代码:
public IEnumerable<T> GetAll<T>(string sql, DynamicParameters parameters, string connectionString, CommandType commandType = CommandType.StoredProcedure)
{
using IDbConnection db = new SqlConnection(connectionString);
var result = db.Query<T>(sql, parameters, commandType: commandType, commandTimeout: COMMAND_TIMEOUT, buffered: false);
return result;
}
Run Code Online (Sandbox Code Playgroud)
当我删除buffered参数时,一切正常。
var result = db.Query<T>(sql, parameters, commandType: commandType, commandTimeout: COMMAND_TIMEOUT);
Run Code Online (Sandbox Code Playgroud)