当我运行带参数的查询或命令时,为什么Dapper会抛出OracleException?

mrt*_*181 15 oracle orm exception oracle11g dapper

我是评价精致但我已经遇到了一些问题.

我想这样做

using (IDbConnection connection = GetConnection())
{
    connection.Open();
    var result = connection.Query(
        "select * from myTable where ID_PK = @a;", new { a = 1 });
}
Run Code Online (Sandbox Code Playgroud)

它在SqlMapper.cs的第393行抛出ORA-00936:缺少表达式OracleException

using (var reader = cmd.ExecuteReader())
Run Code Online (Sandbox Code Playgroud)

当我删除参数时,我将整个表放入结果变量中.

查询在sqldeveloper中没有问题.我正在使用Oracle.DataAccess Assembly 2.112.2.0

mrt*_*181 27

我认为oracle对命名参数有不同的架构,你试过:a而不是@a吗?


小智 5

是的,如果我们尝试在 oracle 数据库表中插入记录,它可以与“:”一起使用。

试试这样:

var count = connection.Execute(@"INSERT INTO COMPANY_USER(UserId , UserName) values (:UserId, :UserName)", new[] { new { UserId = 1, UserName = "Sam" }, new { UserId = 2, UserName = "Don" }, new { UserId = 3, UserName = "Mike" } });
Run Code Online (Sandbox Code Playgroud)