I have a procedure that takes two dates (as strings) and return a result set on DB2400. Using Entity Framework (4.0), I'm seeing the same results with different parameters (when the results ARE different [verified by running the procedure in the iSeries GUI]).
MyEntities.MY_DB2_PROCEDURE('09262013','09262013').ToList();
and
MyEntities.MY_DB2_PROCEDURE('09272013','09272013').ToList();
Build & run with parameters set as seen in the first snippet; 18 records are properly returned. Build and run with the new set of parameters; the same result set is returned.
Again:
CALL MY_DB2_PROCEDURE('09262013','09262013')
and
CALL MY_DB2_PROCEDURE('09272013','09272013')
do produce different results - running against the same DB in the iSeries GUI.
The procedure takes two "date strings" as parameters. I was using this extension method to convert my DateTime
s, causing issues due to single-digit days/months:
public static string ToDateParameter(this DateTime dt)
{
//Format of procedure's parameters: MMDDYYYY
return dt.Month.ToString() + dt.Day.ToString() + dt.Year.ToString();
}
Updated to this and no more errors:
public static string ToDateParameter(this DateTime dt)
{
string day;
string month;
/*
* Format of procedure's parameters: MMDDYYYY
* Procedure expects string of 8 characters for dates; adding 0's in front of single-digit days & months.
*/
day = dt.Day.ToString().Length == 1 ? "0" + dt.Day.ToString() : dt.Day.ToString();
month = dt.Month.ToString().Length == 1 ? "0" + dt.Month.ToString() : dt.Month.ToString();
return month + day + dt.Year.ToString();
}
Initially, I didn't think anything of checking my parameters due to EF errors like:
System.Data.EntityCommandExecutionException: The data reader is incompatible with the specified `Property`. A member of the type, `Property`, does not have a corresponding column in the data reader with the same name.
Update: I did not write the SP and disagree with those parameters. Still, I did not expect to see EF errors rather than DB2 sending me errors back.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.