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

Allow passing an IDictionary<string, object> as parameter object #179

Merged
merged 2 commits into from
Sep 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Dapper NET40/SqlMapper.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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