Dapper not adding parameters

dapper informix odbc sql

Question

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 });
            }
        }
}

Popular Answer

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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why