Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Entity Framework and Report Parameters
posted

I have a report that is using the Entity Framework for its data source.  The report is working fine.  I have added a simple string parameter to the report that I want to filter the results by.  In my ReportDataSourceProvider I inspect the reportParameters dictionary for the parameter and it is found but the value is always something other than what was typed on the screen during report execution.

Value I typed in: timothy

Value I see in code behind for the OperatorName parameter: System.Func`1[System.Object]

Here is my class:

[ReportDataSourceExport(ReportSearchPattern = "ReportOperatorList.*")]
    public class ReportOperatorListDataSourceProvider
                         : IReportDataSourceProviderIDisposable
    {
        private EFModelEntities ctx = new EFModelEntities();
 
        public object GetDataSource(string name, IDictionary<stringParameterValue> reportParameters)
        {
            if (reportParameters.ContainsKey("OperatorName") && reportParameters["OperatorName"].Value != null)
            {
                var opname = reportParameters["OperatorName"].Value.ToString();
 
                if (String.IsNullOrEmpty(opname))
                {
                    return ctx.Operators.OrderBy(c => c.OperatorName);
                }
                else
                {
                    return ctx.Operators.Where(o => o.OperatorName.Contains(opname)).OrderBy(c => c.OperatorName);
                }
            }
            else
            {
                return ctx.Operators.OrderBy(c => c.OperatorName);
            }
        }
 
        public void Dispose()
        {
            ctx.Dispose();
        }
    }

Any ideas on what I am most likely doing wrong?
Parents
  • 195
    Offline posted

    Further research has shown me that my problem isn't with the Entity Framework but only with retrieving the value for the parameter from the reportParameter dictionary collection.

    Code like this does not seem to work for me and I don't know why:

    public object GetDataSource(string name, IDictionary<string, ParameterValue> parameters)
    var customerId = (int) parameters["CustomerId"]; 
    return _ctx.Customers.Where(c => c.CustomerID = customerId)
    }

    I took the above sample code from this URL and tried to make it work in my class in the original post but with no change in results. I am missing something somewhere and I'm not sure what it is.

Reply Children