Commit 116ea975 authored by Marc Gravell's avatar Marc Gravell

Support for ExpandoObject (or at least, "dynamic" and dictionary-like) to be...

Support for ExpandoObject (or at least, "dynamic" and dictionary-like) to be treated directly as a parameter
parent d783008a
...@@ -986,6 +986,16 @@ private static CacheInfo GetCacheInfo(Identity identity) ...@@ -986,6 +986,16 @@ private static CacheInfo GetCacheInfo(Identity identity)
{ {
info.ParamReader = (cmd, obj) => { (obj as IDynamicParameters).AddParameters(cmd,identity); }; info.ParamReader = (cmd, obj) => { (obj as IDynamicParameters).AddParameters(cmd,identity); };
} }
#if !CSHARP30
else if (typeof(IEnumerable<KeyValuePair<string, object>>).IsAssignableFrom(identity.parametersType) && typeof(System.Dynamic.IDynamicMetaObjectProvider).IsAssignableFrom(identity.parametersType))
{
info.ParamReader = (cmd, obj) =>
{
IDynamicParameters mapped = new DynamicParameters(obj);
mapped.AddParameters(cmd, identity);
};
}
#endif
else else
{ {
info.ParamReader = CreateParamInfoGenerator(identity); info.ParamReader = CreateParamInfoGenerator(identity);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
using System.Data; using System.Data;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using System.Dynamic;
#if POSTGRESQL #if POSTGRESQL
using Npgsql; using Npgsql;
#endif #endif
...@@ -788,6 +789,14 @@ public void TestSupportForDynamicParameters() ...@@ -788,6 +789,14 @@ public void TestSupportForDynamicParameters()
p.Get<int>("age").IsEqualTo(11); p.Get<int>("age").IsEqualTo(11);
} }
public void TestSupportForExpandoObjectParameters()
{
dynamic p = new ExpandoObject();
p.name = "bob";
object parameters = p;
string result = connection.Query<string>("select @name", parameters).First();
result.IsEqualTo("bob");
}
public void TestProcSupport() public void TestProcSupport()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment