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

Dapper not mapping bool to bit (as an input parameter) #1436

Open
JRam13 opened this issue Apr 9, 2020 · 4 comments
Open

Dapper not mapping bool to bit (as an input parameter) #1436

JRam13 opened this issue Apr 9, 2020 · 4 comments

Comments

@JRam13
Copy link

@JRam13 JRam13 commented Apr 9, 2020

Take this simple query for example:

bool isDeleted = false;

// Query
SELECT * FROM TableA
WHERE isDeleted = @isDeleted

// Resulting SQL
SELECT * FROM TableA
WHERE isDeleted = False /* @isDeleted */

Why is false mapping to False?

Weirdly enough, it maps bit -> bool just fine.

@mgravell
Copy link
Contributor

@mgravell mgravell commented Apr 10, 2020

I don't understand the question. Dapper doesn't do injection of parameter values (exepct for a very specific case, which isn't this). Dapper simply adds parameters with typed values. There is no "resulting SQL" - Dapper literally doesn't have code to do anything like that!

So: where did your "resulting SQL" come from? Is that some kind of trace? If so, I suspect that it was your ADO.NET provider that performed that step, possibly for a database that doesn't directly support parameters. Now the questions become:

  1. What database/server is this?
  2. What ADO.NET provider is this?
@JRam13
Copy link
Author

@JRam13 JRam13 commented Apr 10, 2020

@mgravell Thanks for the response.

The resulting SQL is what gets translated and sent over the wire as the query string (since input parameters need to be mapped appropriately). I might have wrongfully assumed Dapper did this mapping (in this case turning bool false into False instead of 0).

Anyway, we're using Sql Server (running on Azure), and default ADO.NET provider for Sql (System.Data.SqlClient) - using .Net Core 2.2.

Right now the obvious workaround is converting the bool value into an int... but not really sure why we would need to do that.

@mgravell
Copy link
Contributor

@mgravell mgravell commented Apr 10, 2020

@NickCraver
Copy link
Member

@NickCraver NickCraver commented May 2, 2020

It sounds like something else is going on here - can you provide full repro code? It sounds like your param is getting a .ToString() somewhere and that's not something Dapper or SqlClient would do...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.