Creating Reports in ASP.Net with Entity Framework

asp.net entity-framework reporting-services

Question

We are looking to add Microsoft Reports - SSRS to one of our internal websites.

The database has all the reporting features installed.

The website is using Entity Framework 4 for all data.

I have been able to create a report using the old fashioned way of creating a DataSet (*.XSD) and this works well.

My question though, is it possible to utilise the existing Entity Framework in the site for the data required by the reports? Rather than having to re-invent the wheel and make a whole DataSet, along with relationships etc..

It's a website and not application, so this (http://weblogs.asp.net/rajbk/archive/2010/05/09/creating-an-asp-net-report-using-visual-studio-2010-part-1.aspx) doesn't seem to apply; I don't see the DataSource (in part 2 of the tutorial)

Update

As a side-note, we would like to steer clear of expensive third-party controls etc.

Also, another way to look at the issue might be to generate the *.XSD from the entity framework entity model; is this possible? It's not ideal though would get us up and running..

1
29
3/1/2013 2:48:42 PM

Popular Answer

Below is a quick sample of how i set the report datasource in one of my .NET winForms applications.

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.EndDate,
                                       l.Supervisor,
                                       l.Department,
                                       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;
        }
9
5/7/2015 5:27:15 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow