使用Informix和Dapper向查询添加参数失败,并出现语法异常

Ben*_*Ben 2 c# asp.net-mvc informix dapper

我试图通过ODBC在Informix上使用参数化查询,但任何添加参数的尝试都会失败并出现以下异常:

$exception {"ERROR [42000] [Informix .NET provider][Informix]A syntax error has occurred."} System.Exception {IBM.Data.Informix.IfxException}

这是失败的代码:

List<ItemAttribute> items = con.Query<ItemAttribute>("select * from oe_cnvwrk where cwr_genero = @cwr_genero", new{cwr_genero = cwr_genero}).ToList();

像这个例子一样使用没有参数的它可以完美地工作,但是打开应用程序直到注入攻击:

ItemHeader itemHeader = con.Query<ItemHeader>("select * from oe_cnvhdr where hdr_control_id = " + hdr_control_id).Single();

我能够在这里找到一个关于这个完全相同问题的先前列出的问题,但它从未被回答过.我希望有人会知道如何处理这个问题:Dapper没有添加参数

任何想法都可以解决这个问题,或者是否有一种不同的方法来处理可能有效的Dapper参数化?

Mar*_*ell 5

尚未发布到NuGet,但源代码现在包含对伪位置参数的支持.这些是通过模式识别实现的,这样?abc?在您的文本中映射到从成员命名的参数abc,但使用位置?语法.所以如果你发出:

List<ItemAttribute> items = con.Query<ItemAttribute>(
    "select * from oe_cnvwrk where cwr_genero = ?cwr_genero?",
    new{cwr_genero = cwr_genero}).ToList();
Run Code Online (Sandbox Code Playgroud)

它应该工作; 执行的实际查询是:

select * from oe_cnvwrk where cwr_genero = ?
Run Code Online (Sandbox Code Playgroud)

添加的参数是标记成员的参数cwr_genero.这允许正确解析成员.特殊?foo?模式用作切换到位置参数的指示器.

请注意,每个查询只能引用一次单个参数; 以下将无法正常工作:

select * from sometable where foo = ?x? or bar = ?x?
Run Code Online (Sandbox Code Playgroud)