我的问题类似于这个 但我在实际实施中遇到了一些问题。
我在 3 层应用程序的业务层中有一份报告 (.rdlc)。
我在 BL (EmployeeManager
) 中有一个对象,它有一个 GetEmployees(Expression as Expression(Of Func(Of Employee, Boolean))) As IQueryable(Of Employee)
方法。
由于我不想尝试直接传递 lambda(至少在我有东西可以工作之前),所以我在 BL 中创建了一个 ReportData
类,它包装了 GetEmployees()
调用并将结果公开为 IEnumerable(Of Employee) - 这应该非常简单。目前它甚至没有参数。
好的...所以在我的报告中,我尝试添加一个新的数据源。我选择了一种 Object
类型并找到了上面提到的 ReportData
类。向导完成并向项目添加一个 DataSources 文件夹,其中有一些定义
并指向 Report
类的 XML。
ReportData
也出现在“数据源”窗格中 - 它旁边有一个 >
,但当我展开它时,它没有子项。
我不知道该怎么做是使用数据源 - 它似乎没有公开任何方法/成员(我什至还没有指定它应该调用 GetEmployees()
!)我当然在任何地方都看不到 IEnumerable(Of Employee)
。
当我尝试向报表添加表并提示我选择数据集时,ReportData 数据源未显示在数据源下拉列表中。
我缺少什么?有人可以指出我正确的方向吗?
我的简单 ReportData 对象:
Namespace Reports
Public Class ReportData
Private Property EmployeeManager As Interfaces.IEmployeeManager
Public Sub New()
''This sub is here in case it's an instantiation problem - I intend to use dependency injection when I've got this working properly.
Me.EmployeeManager = New EmployeeManager
End Sub
Public Sub New(ByVal EmployeeManager As Interfaces.IEmployeeManager)
Me.EmployeeManager = EmployeeManager
End Sub
Public Function GetEmployees() As IEnumerable(Of Employee)
Return EmployeeManager.GetEmployees()
End Function
End Class
End Namespace
我还发现 this 这似乎表明我遵循正确的步骤,但属性未按预期显示
该类的公共属性现在显示在“数据源”窗口中,可以将它们拖放到报表中。
这不会发生 - 属性永远不会出现
编辑:正如亚历克斯所指出的,我需要使用属性而不仅仅是任何方法。请参阅下面 Alex Esselfie 的回答以进行澄清。这仍然没有解决我的问题,但让我更近了一步......
My question is similar to this one but I'm having some problems with the actual implementation.
I've got a report (.rdlc) in the business layer of a 3-tier app.
I've got an object in the BL (EmployeeManager
) which has a GetEmployees(Expression as Expression(Of Func(Of Employee, Boolean))) As IQueryable(Of Employee)
method.
As I didn't want to try and pass a lambda in directly (at least not until I've got something working), I've created a ReportData
class in the BL which wraps the GetEmployees()
call and exposes the results as an IEnumerable(Of Employee) - which should be very simple. It doesn't even have parameters at the moment.
Ok... So In my report, I've tried to add a new Data Source. I've picked a type of Object
and located the ReportData
class mentioned above. The wizard completes and adds a DataSources folder to the project inside which is some XML defining a <GenericObjectDataSource>
and pointing at the Report
class.
ReportData
also appears in the Data Sources pane - It has a >
next to it but when I expand it, it has no children.
What I don't know how to do is USE the data source - It doesn't seem to expose any methods/members (I haven't even specified that it should call GetEmployees()
yet!) and I certainly can't see an IEnumerable(Of Employee)
anywhere.
When I try to add a table to the report and it prompts me to select a Dataset, the ReportData Datasource is not shown in the Data source drop-down.
What am I missing? Can someone please point me in the right direction?
My simple ReportData object:
Namespace Reports
Public Class ReportData
Private Property EmployeeManager As Interfaces.IEmployeeManager
Public Sub New()
''This sub is here in case it's an instantiation problem - I intend to use dependency injection when I've got this working properly.
Me.EmployeeManager = New EmployeeManager
End Sub
Public Sub New(ByVal EmployeeManager As Interfaces.IEmployeeManager)
Me.EmployeeManager = EmployeeManager
End Sub
Public Function GetEmployees() As IEnumerable(Of Employee)
Return EmployeeManager.GetEmployees()
End Function
End Class
End Namespace
I've also found this which seems to indicate I'm following the correct steps but the properties don't appear as expected
The public properties of the class now appear in the Data Sources window, where they can be dragged and dropped into the report.
This doesn't happen - the properties never appear
EDIT: As pointed out by Alex, I need to use properties not just any methods. Please see Alex Esselfie's answer below for clarification. This still hasn't solved my problem but has got me a step closer...
发布评论
评论(2)
根据您的描述和随附的代码,
ReportData
类中没有属性。如果我猜得好,该类应该生成您想要在报告上显示的 IEnumerable 。如果是这种情况,您必须在向导中选择
Employee
类作为数据源。这将允许您在报告上显示数据。我将开展一个快速项目,并稍后将其添加到此答案中。
编辑 1
如何将类绑定到报表
Visual Studio 2008
Data
>显示数据源
在您的情况下,您绑定到 Employee 类。
Visual Studio 2010
View
>报告数据
新建
> “数据源”窗口中的数据集...
。创建新数据源或选择现有数据源。
创建新数据源
将类绑定到报告后,继续像往常一样设计您的报告。
编辑2
我为您上传了一个示例项目。这是链接.
如果您需要进一步说明,请通知我,以便我为您提供有关如何复制该项目的分步过程。
From your description and accompanying code, there are no properties in the
ReportData
class. If I reckon well, that class is supposed to be generating theIEnumerable
you want to display on the report.If that's the case, you'll have to select the
Employee
class as the DataSource in the wizard. This will allow you to display the data on your report.I'll work on a quick project and add it to this answer in a moment.
Edit 1
How to Bind a Class to a Report
Visual Studio 2008
Data
>Show Data Sources
In your case, you bind to the Employee class.
Visual Studio 2010
View
>Report Data
New
>Dataset...
on the Data Sources window.Create a New Data source or select an existing data source.
Creating a New Data source
After binding a class to the report, go ahead and design your report as usual.
Edit 2
I uploaded a sample project for you. Here's the link.
If you need further clarification, please notify me so I give you a step by step procedure on how to replicate the project.
我也有同样的问题。我必须向表示层添加一个数据源(对象类型),该数据源指向业务层中的对象(具有属性类的集合)。我在表示层中创建了报告(.rdlc)并将其指向数据源并且一切正常。这是我发现向报告公开字段属性的唯一方法。在运行时,我将报告数据源绑定到集合。我喜欢在业务层设计一个“平面”集合,处理数据并将其发送到 rdlc,使报告尽可能“哑”。
I had the same problem. I had to add a Data Source (Object Type) to my presentation layer that pointed to my Object in the Business layer (collection with property class). I created the report (.rdlc) in the presentation layer and pointed it to the Data Source and everthing working fine. This was the only way I found to expose the field properties to the report. At runtime I bind the report datasource to the collection. I like to design a "flat" collection in the business layer, process the data and send it to the rdlc keeping the report as "dumb" as possible.