Skip to main content
 首页 » 编程设计

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

2024年02月23日14zengkefu

我要显示表格的数据。而且我无法显示它们引用的表中的值,而不是字段 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();