How to set parameters in context.Query
Posted: Thu 19 Jul 2012 03:08
This is the example:
I'd like to set parameters (:PARAMETER_IDRUN) in context.Query<T>, but how can I do this?
I tried
then run
but failed, it shows ORA-01008: not all variables bound.
PS: I know there is another way to set Parameters like:
but it looks like not suitable for me because I need to return IQuerable<T> and use deferred execution.
Code: Select all
string sql = SELECT * FROM POSITION where IDRUN=:PARAMETER_IDRUN ;
IQueryable<T> results = context.Query<T>(sql);
I tried
Code: Select all
string command = string.Format("declare "
+ "PARAMETER_IDRUN number; "
+ "begin "
+ "PARAMETER_IDRUN := -172; "
+ " End;");
context.ExecuteCommand(command);
Code: Select all
IQueryable<T> results = context.Query<T>(sql);
PS: I know there is another way to set Parameters like:
Code: Select all
OracleCommand ocmd = oc.CreateCommand();
ocmd.ParameterCheck = true;
ocmd.CommandText = "select :p1,:p2 from dual";
ocmd.Prepare();
ocmd.Parameters["p1"].Value = "00000";
ocmd.Parameters["p2"].Value = "00001";
OracleDataReader or = ocmd.ExecuteReader();