Search code examples
c#asp.netentity-frameworkstored-procedurescrystal-reports

Crystal Reports return "DataSet does not support System.Nullable" with Stored Procedure


I'm having an issue displaying a Crystal Report on my ASP .NET Web Project. This is my "View Report" button code:

private void ViewReport(int bankID, DateTime dateFrom, DateTime dateTo)
{
   ReportDocument report = new ReportDocument();
   report.Load(Server.MapPath("~\\Reports\\rptBankTransactionsList.rpt"));
   report.SetDataSource(bankEntities.spBankTransactionsList(bankID, dateFrom, dateTo).ToList());
   report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "TransactionsList");
}

I'm using Entity Framework, and the spBankTransactionsList stored procedure is returning the right values. I'm even using the exact same stored procedure to display the result in a GridView with no problems. The report is using a DataSet with the exact same result values of the stored procedure.

This is the stored procedure:

ALTER PROCEDURE [dbo].[spBankTransactionsList] 
@bankID AS INT,
@dateFrom AS DATETIME2,
@dateTo AS DATETIME2
AS

BEGIN

    SELECT B.BankID, B.BankName, BT.Date, BT.Description, BT.Amount
    FROM Bank B
    INNER JOIN BankTransaction BT ON B.BankID = BT.BankID
    WHERE B.BankID = @bankID
    AND BT.Date BETWEEN @dateFrom AND @dateTo
END

I have several reports with the same situation and this is the only one that is returning me the "DataSet does not support System.Nullable" error when loading the report. The stored procedure results are not displaying any null value, as I said, the results in the GridView are OK.

If the rows of the stored procedure results are zero, the report loads fine, obviously with no records but it loads! What am I missing?

Thanks in advace.


Solution

  • The issue was keep coming in other reports and SPs, so finally I came up with the solution.

    Although in my SPs I make sure that there's no null values on the results, somehow, when Entity Framework gets the SP into the model, it "assumes" that some columns might be nullable.

    The solution for this is going to Model Explorer, select the Entity Model, then search the results type of the SP in Complex Types (in my case was "spBankTransactionsList_Results", expand it and check that every property has the nullable values to false.

    Hope this hepls someone else with the same issue.