Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert<T> return non-int #144

Open
tess-hartis opened this issue Sep 5, 2022 · 2 comments
Open

Insert<T> return non-int #144

tess-hartis opened this issue Sep 5, 2022 · 2 comments

Comments

@tess-hartis
Copy link

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

@aravindk777
Copy link

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

@tess-hartis
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants