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 Reply Children