Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Dapper throw an OracleException when i run a query or command with parameters?

I am evaluation dapper but i already running into some problems.

I am trying to do this

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

It throws an ORA-00936: missing expression OracleException at line 393 in the SqlMapper.cs

using (var reader = cmd.ExecuteReader())

When i remove the parameter i get the whole table into the result variable.

The query works without problems in sqldeveloper. I am using the Oracle.DataAccess Assembly 2.112.2.0

like image 257
mrt181 Avatar asked Aug 10 '11 14:08

mrt181


People also ask

What is Dynamicparameters?

Dynamic parameters can be strings, measure values, or dates, offering flexibility and interactivity when building a dashboard for your audience. Because they can be easily used in most analytical entities, dynamic parameters give you programmatic control to customize your analysis.


3 Answers

I think oracle has a different schema for named parameter, did you try :a instead of @a?

like image 141
mrt181 Avatar answered Sep 22 '22 16:09

mrt181


Yes, it works with ":" if we trying to insert records in oracle database table.

Just try like this:

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" } }); 
like image 23
user3120244 Avatar answered Sep 24 '22 16:09

user3120244


It also works with IN list:

var partialList = new List();

var list = await db.QueryAsync("select bla1, blah2 FROM tablename WHERE stringcolumn1 IN :ListofValues", new { ListofValues = partialList });

like image 39
Boguslaw Buczek Avatar answered Sep 23 '22 16:09

Boguslaw Buczek