quaiton89 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

PackListParameters is only called when using anonymous class #115

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use IEnumerable parameter like array of ints
2. Use ExpandoObject object cast to dynamic and add that list parameter to it
3. Or use DynamicParameters.Add methods
4. Then try to use your list parameter like 'Id IN @MyListParameter'

What is the expected output? What do you see instead?
Expect it to work like using anonymous class as parameter new { MyListParameter 
= myList }

I see this
System.ArgumentException : No mapping exists from object type 
System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider 
native type.

What version of the product are you using? On what operating system?
Microsoft SQL Server 2008 R2

Please provide any additional information below.

Works
var parameters = DynamicParameter();
parameters.AddDynamicParams(new { MyListParameter = myList });

And this

dynamic parameters = new { MyListParameter = myList };

This doesn't work
var parameters = DynamicParameter();
parameters.Add("MyListParameter", myList); 

Nor this 
var parameters = new ExpandoObject();
parameters.MyListParameter = myList

Original issue reported on code.google.com by jussi.ha...@gmail.com on 27 Sep 2012 at 1:38

GoogleCodeExporter commented 8 years ago
Thanks for providing a syntax that does work! (For the mean time..)

Original comment by jedidja...@gmail.com on 26 Mar 2013 at 6:54

GoogleCodeExporter commented 8 years ago
Is there any update on this? I have a situation where I have a dynamic number 
of params so an ExpandoObject would be perfect - but even just being able to 
use the DynamicParameter object would be fine. (Note: this issue only occurs 
with collection/enumerable objects - I can use DynamicParameter quite happily 
with simple object types).

Original comment by craig.wa...@xero.com on 25 Feb 2014 at 8:49

GoogleCodeExporter commented 8 years ago
Here is a workaround for you. I had the same exact problem and you can do like 
this.
var parameters = new DynamicParameters();
parameters.AddDynamicParams(new { MyListParameter = myList });

Original comment by jussi.ha...@gmail.com on 25 Feb 2014 at 8:57

GoogleCodeExporter commented 8 years ago
That's not a workaround I can use - I don't know the parameters at compile time 
- only at runtime.

Original comment by craig.wa...@xero.com on 25 Feb 2014 at 9:03

GoogleCodeExporter commented 8 years ago
Try this, it will work.

var parameters = new DynamicParameters();
parameters.AddDynamicParams(new Dictionary<string, object>() { { 
"MyListParameter", myList } });

Original comment by jussi.ha...@gmail.com on 25 Feb 2014 at 9:17

GoogleCodeExporter commented 8 years ago
I meant it might work :)

Original comment by jussi.ha...@gmail.com on 25 Feb 2014 at 9:18