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

fix Insert<T> when T is declared as IEnumerable<T> #948

Merged
merged 1 commit into from
Mar 30, 2018
Merged

fix Insert<T> when T is declared as IEnumerable<T> #948

merged 1 commit into from
Mar 30, 2018

Conversation

bdrupieski
Copy link
Contributor

When inserting, when checking if the type implements IEnumerable<>, we weren't checking that the passed type is itself declared as IEnumerable<>. IEnumerable<> doesn't implement IEnumerable<>; it is IEnumerable<>.

This PR changes adds a check for if the type is itself IEnumerable<> in addition to if it implements IEnumerable<>.

This fixes #930.

@NickCraver
Copy link
Member

Thanks for the fix!

@NickCraver NickCraver merged commit 6e9099d into DapperLib:master Mar 30, 2018
@jons-aura
Copy link

Is there a release planned? I'm pretty sure this is what is breaking inserting lists of objects with Dapper.Contrib for me. I get

 {System.InvalidOperationException: An enumerable sequence of parameters (arrays, lists, etc) is not allowed in this context
   at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1686
   at Dapper.SqlMapper.QueryMultipleImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1012
   at Dapper.SqlMapper.QueryMultiple(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 998
   at SqlServerAdapter.Insert(IDbConnection connection, IDbTransaction transaction, Nullable`1 commandTimeout, String tableName, String columnList, String parameterList, IEnumerable`1 keyProperties, Object entityToInsert) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 784
   at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable`1 commandTimeout) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 355
   at MMA.Data.MMA.Dapper.MMAProvider.Create(IEnumerable`1 parts) in C:\_source\Client\application\MMA.Data\MMA.Dapper\MMAProvider.cs:line 69
   at MMA.Business.Imports.PartImport.ImportParts() in C:\_source\Client\application\MMA.Business\Imports\PartImport.cs:line 80}

@bdrupieski
Copy link
Contributor Author

@NickCraver When this is included in a release I think we should also include #887 so that insert, update, and delete have consistent behavior.

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

Successfully merging this pull request may close these issues.

Dapper.Contrib 1.50.0 -> 1.50.4 broke InsertAsync(IEnumerable)
3 participants