Dapper not adding parameters

删除回忆录丶 提交于 2019-12-10 18:45:46

问题


I am trying to use Dapper for our complex queries to remove any lost overhead that was previously existing with NH.

I have the following query (note this has been considerably shrunk):

SELECT DISTINCT *
FROM  tasks t 
WHERE t.initials = @UserInits

Which is called via our repository as so:

taskRepo.RawExec<TaskListItemDTO>(Query,new {UserInits = "SAS"})

Our implementation of DapperExec consist as follows:

public IEnumerable<T> RawExec<T>(string SQL, object param)
{
   return _session.Connection.Query<T>(SQL,param);
}

But Dapper doesn't appear to be adding the parameters to the query, and as a result, we are getting syntax errors.

Incase it helps, we are connecting over ODBC to Informix.

Thanks

Update Code Sample:

Sorry it took so long, been very busy with work! Below is a sample for MS SQL (2008) Server that should simple query the sys.all_objects (systables?) with a param value of 1 or 0 - but in this sample, as ODBC does not use named params, this won't work.

using Dapper;
using DapperSQL;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;

namespace DapperTests
{
    public class SQLEx
    {
        private OdbcConnection GetConnection()
        {
            var cnn = new OdbcConnection("DSN=ODBCSOURCE");
            cnn.Open();

            // wrap the connection with a profiling connection that tracks timings 
            return cnn;
        }

        public IEnumerable<object> DapperTest()
        {
            using (OdbcConnection conn = GetConnection())
            {
                return conn.Query("SELECT * FROM sys.all_objects where is_ms_shipped = ?", new { is_ms_shipped = 1 });
            }
        }
}

回答1:


I know this is old post, just use SP instead of query, please check this link Dapper using ODBC store procedure Input parm, this using sybase odbc Sp, all odbc use same technique, I wish it works in Informix.



来源:https://stackoverflow.com/questions/12509791/dapper-not-adding-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!