Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Using WHERE IN statement with custom type handlers results in "No mapping exists from object type ... to a known managed provider native type"

Open CodingBeagle opened this issue 2 years ago • 1 comments

I'm not sure whether or not I'm doing something wrong with the library, however:

I have a custom type handler for one of my classess. When I use this type handler in general use with dapper, I have no issue with it being used properly when executing, say, inserts or querying for the data.

However, the moment I use, say, SELECT statements using WHERE IN, the query always fails with the error mentioned in the title, that is: "Using WHERE IN statement with custom type handlers results in "No mapping exists from object type ... to a known managed provider native type".

An example of such a query would be: var readItem = await connection.QueryAsync<TestString>($"SELECT * FROM HelloWorld WHERE MyColumn IN @Vals", new { Vals = new List<TestString> { item1, item2 }.ToArray() });

Here, "TestString" is my custom type. it is for now simply a class with a single string property. I use a parameterized SQL statement with anonymous objects. I convert the list to an array because I've seen somewhere that it fixed the issue for others. However, it did not fix it for me.

Again, in all other use cases so far I've had no issues. It's the moment I introduce WHEREIN that things start to go haywire.

CodingBeagle avatar Sep 21 '23 09:09 CodingBeagle

Might be related to #1965

bmadzinski avatar Sep 21 '23 22:09 bmadzinski