Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting Services using Entity Framework

I had experience in developing reports(SSRS) using ado.net dataset. Now I am working on an application which is not using ADO.net but entity framework but entity framework does not return datatable or dataset. I want to know

  1. Is there any way to use Collection or custom objects return by entity framework in the reporting services?
  2. Entity framework somehow return datatable or dataset.

Or I should create datatable/dataset from the collection returned by entity framework manually.

For the record, I am getting resultset by executing stored procedure from entity framework.

like image 703
Manvinder Avatar asked Sep 04 '13 13:09

Manvinder


1 Answers

public void getMyReportData() 
{ 
     using (myEntityDataModel v = new myEntityDataModel()) 
     {

         var reportQuery = (from r in v.myTable
                               select new
                               {
                                   l.ID,
                                   l.LeaveApplicationDate,
                                   l.EmployeeNumber,
                                   l.EmployeeName,
                                   l.StartDate,
                                   l.Col1,
                                   l.Col2,
                                   .......,
                                   .......,
                                   l.Address
                               }).ToList();

        reportViewer1.LocalReport.DataSources.Clear();
        ReportDataSource datasource = new ReportDataSource("nameOfReportDataset", reportQuery);
        reportViewer1.LocalReport.DataSources.Add(datasource);

        Stream rpt = loadEmbededReportDefinition("Report1.rdlc");
        reportViewer1.LocalReport.LoadReportDefinition(rpt);
        reportViewer1.RefreshReport();

        //Another way of setting the reportViewer report source

        string exeFolder = Path.GetDirectoryName(Application.ExecutablePath);
        string reportPath = Path.Combine(exeFolder, @"rdlcReports\Report1.rdlc");
        reportViewer1.LocalReport.ReportPath = reportPath;

        reportParameter p = new ReportParameter("DeptID", deptID.ToString());
        reportViewer1.LocalReport.SetParameters(new[] { p });

    }
}




public static Stream loadEmbededReportDefinition(string reportName)
    {
        Assembly _assembly = Assembly.GetExecutingAssembly();
        Stream _reportStream = _assembly.GetManifestResourceStream("ProjectNamespace.rdlcReportsFolder." + reportName);

        return _reportStream;
    }

Original source: Creating Reports in ASP.Net with Entity Framework

like image 123
Mike Beeler Avatar answered Sep 28 '22 18:09

Mike Beeler