DapperLib/Dapper.Contrib

Insert<T> return non-int

tess-hartis opened this issue · 2 comments

Will there ever be an overload of the Insert extension that can return an identity value that is not an integer?

I have this question too. Also the documentation seems wrong. The actual underlying implementation is using return connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout); which is returning the number of rows affected and that is what being returned and its not the identity value.

The InsertAsync() has the wrong documentation about its return type property.
Wrong documentation:

    /// <summary>
    /// Inserts an entity into table "Ts" asynchronously using Task and ** returns identity id. **
    /// </summary>
    /// <typeparam name="T">The type being inserted.</typeparam>
    /// <param name="connection">Open SqlConnection</param>
    /// <param name="entityToInsert">Entity to insert</param>
    /// <param name="transaction">The transaction to run under, null (the default) if none</param>
    /// <param name="commandTimeout">Number of seconds before command execution timeout</param>
    /// <param name="sqlAdapter">The specific ISqlAdapter to use, auto-detected based on connection if null</param>
    /// <returns>Identity of inserted entity</returns>
    public static Task<int> InsertAsync<T>(this IDbConnection connection, T entityToInsert, IDbTransaction transaction = null,
        int? commandTimeout = null, ISqlAdapter sqlAdapter = null) where T : class

@aravindk777

You are right, the documentation seems wrong. To achieve the desired result, maybe there would have to be another implementation of Insert which takes a tuple, Insert<Type, ReturnValueType>, and then uses ExecuteScalarAsync.