c# - 无法显示链接字段值表+ReportViewer

标签 c# .net asp.net report

我要显示表格的数据。而且我无法显示它们引用的表中的值,而不是字段 ID。

我添加了新项目 - Reportint-> Report (*.rdcl),然后在 Web 表单 ReportViewer 上添加。 VS 已显示向导,我添加了新的数据集,在其中选择我的业务方法来选择数据。

我有表 Inhabitans,它包含 FacultyID 字段,但我想从链接表中查看值,其中 Inhabitans.FacultyID == Faculty.FacultyID。

public List<Inhabitant> SelectAllWithoutParameters()
    {
        using (DataContext dc = Infrastructure.DataContext)
        {
            DataLoadOptions options = new DataLoadOptions();
            options.LoadWith<Inhabitant>(u => u.Faculty);
            dc.LoadOptions = options;
            List<Inhabitant> inhs = dc.GetTable<Inhabitant>().OrderBy(u => u.FullName).ToList();
            return inhs;
        }
    }

单击插入 - 新表。我可以选择 Inhabitant 中的所有字段,但不能选择 Faculty 中的所有字段。

如何解决这个问题

最佳答案

我对 rdcl 报告一无所知,但我会创建一个新类来将数据转换到其中,例如 InhabitantReport。

然后你只要改变这一行:

List<Inhabitant> inhs = dc.GetTable<Inhabitant>().OrderBy(u => u.FullName).ToList();

像这样:

List<InhabitantReport> inhs = dc.GetTable<Inhabitant>().OrderBy(u => u.FullName).Select(r=>new InhabitantReport() 
{
 //Populate data.
}).ToList();

关于c# - 无法显示链接字段值表+ReportViewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6168295/

相关文章:

c# - 进行网络 I/O 时 Stream.Read 是否被缓冲?

c# - MIDI 声音仅在一个 channel (左或右)

c# - .NET 的 GUID 结构

c# - 异步调用 webservice 方法

c# - 在更新面板中回发后,Bootstrap 工具提示消失

asp.net - 如何使用 MSBuild 为此项目文件夹中的所有文件创建 MSdeploy 包

c# - 使用 C# 在 asp.net 中的 SQL Server 中保存和检索图像

c# - Grid Splitter 在对角线上工作?

C# 将文本转语音保存到MP3文件

.net - 如何读取嵌入的资源文本文件