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 DateTimes, 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top