问题描述
我们希望将 Microsoft Reports - SSRS 添加到我们的内部网站之一.
We are looking to add Microsoft Reports - SSRS to one of our internal websites.
数据库已安装所有报告功能.
The database has all the reporting features installed.
该网站对所有数据使用实体框架 4.
The website is using Entity Framework 4 for all data.
我已经能够使用创建数据集 (*.XSD) 的老式方法创建报告,并且效果很好.
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..
这是一个网站而不是应用程序,所以这个 (http://weblogs.asp.net/rajbk/archive/2010/05/09/creating-an-asp-net-report-using-visual-studio-2010-part-1.aspx) 似乎不适用;我没有看到数据源(在教程的第 2 部分)
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)
更新
作为旁注,我们希望避开昂贵的第三方控件等.
As a side-note, we would like to steer clear of expensive third-party controls etc.
此外,另一种看待问题的方法可能是从实体框架实体模型生成 *.XSD;这可能吗?这并不理想,但会让我们启动并运行..
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..
推荐答案
以下是我如何在我的一个 .NET winForms 应用程序中设置报表数据源的快速示例.
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, @"rdlcReportsReport1.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;
}
这篇关于使用实体框架在 ASP.Net 中创建报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!