Parameterizing a raw Oracle SQL query in Entity Framework Parameterizing a raw Oracle SQL query in Entity Framework oracle oracle

Parameterizing a raw Oracle SQL query in Entity Framework


First, like Mohammed wrote, you need to prefix the parameter with ':', but not as you define it, just in the query.Second, you are currently searching not for the value of the parameter but rather strings that contains the string @param1. So surround the value of the parameter with % and you should get a result.

So it should look something like this:

string term="foo"; OracleParameter p = new OracleParameter("param1", term); object[] parameters = new object[] { p }; var model = db.Database.SqlQuery<ProjectTask>("SELECT * FROM (SELECT * FROM web_project_task_vw WHERE project_num like '%'||:param1||'%') WHERE rownum<=100", parameters).ToList();


Your p might have an incorrect parameter name; the name should be param1, not @param1. Your query is also incorrect; replace '%@param1%' with '%:param1%'.