Passing query parameters in Dapper using OleDb

前端 未结 4 1200
逝去的感伤
逝去的感伤 2020-12-03 21:55

This query produces an error No value given for one or more required parameters:

using (var conn = new OleDbConnection(\"Provider=...\"))
{
  co         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 21:59

    I've trialing use of Dapper within my software product which is using odbc connections (at the moment). However one day I intend to move away from odbc and use a different pattern for supporting different RDBMS products. However, my problem with solution implementation is 2 fold:

    1. I want to write SQL code with parameters that conform to different back-ends, and so I want to be writing named parameters in my SQL now so that I don't have go back and re-do it later.
    2. I don't want to rely on getting the order of my properties in line with my ?. This is bad. So my suggestion is to please add support for Named Parameters for odbc.

    In the mean time I have hacked together a solution that allows me to do this with Dapper. Essentially I have a routine that replaces the named parameters with ? and also rebuilds the parameter object making sure the parameters are in the correct order. However looking at the Dapper code, I can see that I've repeated some of what dapper is doing anyway, effectively it each parameter value is now visited once more than what would be necessary. This becomes more of an issue for bulk updates/inserts. But at least it seems to work for me o.k...

    I borrowed a bit of code from here to form part of my solution...

提交回复
热议问题