Open j-caetano opened 1 month ago
Hey, found an issue regarding the null safety on return type of OrDefault methods on IDapperSqlBuilderExtensions as these methods can return null.
OrDefault
IDapperSqlBuilderExtensions
The FirstOrDefault/SingleOrDefault extension methods return non-nullable types while using the Dapper methods that return a nullable generic type.
FirstOrDefault
SingleOrDefault
Dapper:
public static Task<T?> QueryFirstOrDefaultAsync<T>(this IDbConnection cnn, string sql, object? param = null, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) => QueryRowAsync<T?>(cnn, Row.FirstOrDefault, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default))
InterpolatedSql.Dapper: IDapperSqlBuilderExtensions.cs
IDapperSqlBuilderExtensions.cs
public static T QueryFirstOrDefault<T>(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.QueryFirstOrDefault<T>(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); }
Adding a nullable return type would solve the issue
public static T? QueryFirstOrDefault<T>(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.QueryFirstOrDefault<T>(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); }
Would you like to submit a PR?
Hey, found an issue regarding the null safety on return type of
OrDefault
methods onIDapperSqlBuilderExtensions
as these methods can return null.The
FirstOrDefault
/SingleOrDefault
extension methods return non-nullable types while using the Dapper methods that return a nullable generic type.Dapper:
InterpolatedSql.Dapper:
IDapperSqlBuilderExtensions.cs
Adding a nullable return type would solve the issue