Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created this model object in C# and want to create a report with sub report and don't know how to link the 2; Here is my model
C#
public class LabReport  
{  
    public int ref_id{get;set;}  
    public String t_name { get; set; }  
    public IList<LabSubReport> result { get; set; }//this where i need subreport  
}  
public class LabSubReport  
{  
    public int ref_id { get; set; }//foreign key from Above model  
    public String l_test { get; set; }  
    public String t_value { get; set; }  
}

more explanation of the problem is here:
Creating subreport in cystal report[^]

What I have tried:

and this is how Have populated my model
C#
IList<LabReport> report=new List<LabReport>();  
IList<LabRequestEntity> empo =//dao to fetch data  
int count = 1;  
foreach (LabRequestEntity e in empo)  
{  
    IList<LabTestNoteEntity>  notes=e.test_note;//entity relation ship here  
    IList<LabSubReport> sublist=new List<LabSubReport>();  
      
     
    foreach(LabTestNoteEntity p in notes)  
    {  
       var sub=new LabSubReport()  
       {  
          l_test=p.test,  
          t_value=p.result  
       };  
       sublist.Add(sub);  
    }  
  
    var rpt = new LabReport()  
    {  
        ref_id = "" + count,  
        t_name=e.lab_test.t_name,  
        result=sublist  
          
    };  
    count++;  
    report.Add(rpt);  
}

C#
ReportDocument cryRpt = new ReportDocument();  
cryRpt.Load("C:/MainReport.rpt");  
cryRpt.DataSourceConnections.Clear();  
cryRpt.SetDataSource(report);  
cryRpt.Subreports[0].DataSourceConnections.Clear();  
cryRpt.Subreports[0].SetDataSource(report.select(x=>x.result));//this is where error is occuring

and getting this error
Column 'ref_id' does not belong to table LabSubReport
Posted
Updated 10-Jan-21 3:08am
v6
Comments
[no name] 17-Dec-20 10:39am    
You're just throwing code around:

IList<labreport> report=report=new List<labreport>();
Member 13723368 17-Dec-20 10:47am    
@Gerry Schmitz what do you recommend me to do
Afzaal Ahmad Zeeshan 17-Dec-20 23:28pm    
Reply to the author's comment to notify them of your reply.
[no name] 18-Dec-20 15:07pm    
Unless you can find a "working example" on the DevExpress (site) forums, you will NOT find it anywhere else. If people did it routinely, you'd hear about it. Find a different project.
Member 13723368 19-Dec-20 2:47am    
I thought u are helping to fix where the error is??

1 solution

I see at least 1 syntax error
C#
var rpt = new LabReport()  
    {  
        ref_id = "" + count,  <===== ref_id is defined as an int. This won't work
        t_name=e.lab_test.t_name,  
        result=sublist  
          
    };  


Also if your classes of LabReport and LabSubReport are entities within Entity Framework and ref_id is supposed to be a Foreign Key, you might try adding the decorator for the Foreign Key to prevent LabSubReport from generating a ref_id when it's constructed.

C#
public class LabSubReport  
{  
    [ForeignKey("ref_id")]
    public int ref_id { get; set; }//foreign key from Above model  
    public String l_test { get; set; }  
    public String t_value { get; set; }  
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900