Skip to content

Commit

Permalink
Merge pull request #179 from matwilko/idictionary-fix
Browse files Browse the repository at this point in the history
Allow passing an IDictionary<string, object> as parameter object
  • Loading branch information
mgravell committed Sep 22, 2014
2 parents dc17868 + d2cce62 commit 5abf74f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Dapper NET40/SqlMapper.cs
Expand Up @@ -2048,17 +2048,19 @@ private static CacheInfo GetCacheInfo(Identity identity, object exampleParameter
{
info.ParamReader = (cmd, obj) => { ((IDynamicParameters)obj).AddParameters(cmd, identity); };
}
#if !CSHARP30
// special-case dictionary && `dynamic`
else if (exampleParameters is IEnumerable<KeyValuePair<string, object>> && exampleParameters is System.Dynamic.IDynamicMetaObjectProvider)
#if CSHARP30
else if (exampleParameters is IEnumerable<KeyValuePair<string, object>>)
#else
// special-case dictionary and `dynamic`
else if (exampleParameters is IEnumerable<KeyValuePair<string, object>> || exampleParameters is System.Dynamic.IDynamicMetaObjectProvider)
#endif
{
info.ParamReader = (cmd, obj) =>
{
IDynamicParameters mapped = new DynamicParameters(obj);
mapped.AddParameters(cmd, identity);
};
}
#endif
else
{
var literals = GetLiteralTokens(identity.sql);
Expand Down
9 changes: 9 additions & 0 deletions Tests/Tests.cs
Expand Up @@ -3842,6 +3842,15 @@ public void SO25297173_DynamicIn()
result.Contains(6).IsTrue();
}

public void AllowIDictionaryParameters()
{
var parameters = new Dictionary<string, object>
{
{ "param1", 0 }
};

connection.Query("SELECT @param1", parameters);
}
#if POSTGRESQL

class Cat
Expand Down

0 comments on commit 5abf74f

Please sign in to comment.