Dapper不添加参数 [英] Dapper not adding parameters

查看:162
本文介绍了Dapper不添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Dapper进行复杂查询,以消除NH以前存在的所有开销.

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

我们对DapperExec的实现如下:

Our implementation of DapperExec consist as follows:

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

但是Dapper似乎没有在查询中添加参数,因此,我们遇到语法错误.

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

如果有帮助,我们将通过ODBC连接到Informix.

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

谢谢

更新代码示例:

很抱歉,花了很长时间,一直忙于工作!以下是用于MS SQL(2008)Server的示例,该示例应简单查询参数值为1或0的sys.all_objects(systables?)-但在此示例中,由于ODBC不使用命名的参数,因此将无法正常工作

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

推荐答案

我知道这是旧帖子,只使用SP而不是查询,请检查此链接

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.

这篇关于Dapper不添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆