Error in FlexReport Subreport with EntityFramework recordset

Posted by: cortiz on 27 December 2017, 12:34 am EST

    • Post Options:
    • Link

    Posted 27 December 2017, 12:34 am EST

    I have been trying to use entity framework to populate the recordset datasource of the report. I have written two methods that change the recordset. The first uses entity directly and populates the master report but throws an error in the sub-report.

    
    public C1FlexReport BuildSubReport2()
            {
                // example using recordset
                C1FlexReport report = new C1FlexReport();
                List<CLIENT1> clients;
                List<Parcel> parcels;
                using (ClientContext context = new C1Report_Example.ClientContext())
                {
                    clients = context.CLIENT1.Where(a => a.ID.StartsWith("AA")).ToList();
                    parcels = context.Parcel.Where(a => a.ID.StartsWith("AA")).ToList();
                }
    
                report.Load("TestReports.flxr", "TestReport1");
                report.DataSource.Recordset = clients;
    
                SubreportField field = (SubreportField)report.Fields["Field1"];
                C1FlexReport subReport = field.Subreport;
    
                subReport.DataSource.Recordset = parcels;
                //report.Render();
                //report.Print();
                return report;
            }
    
    

    The second uses entity and creates a datatable (using the MoreLinq extension) and does not throw and error.

    
    public C1FlexReport BuildSubReport4()
            {
                // example using recordset
                C1FlexReport report = new C1FlexReport();
                DataTable clients;
                DataTable parcels;
                using (ClientContext context = new C1Report_Example.ClientContext())
                {
                    clients = context.CLIENT1.Where(a => a.ID.StartsWith("BB")).ToDataTable<CLIENT1>();
                    parcels = context.Parcel.Where(a => a.ID.StartsWith("BB")).ToDataTable<Parcel>();
                }
    
                    report.Load("TestReports.flxr", "TestReport1");
                    report.DataSource.Recordset = clients;
    
                    SubreportField field = (SubreportField)report.Fields["Field1"];
                    C1FlexReport subReport = field.Subreport;
    
                    subReport.DataSource.Recordset = parcels;
    
                
                //report.Render();
                //report.Print();
                return report;
            }
    
    

    I have attached screenshots of the error and a functioning report. Am I doing something wrong?

  • Posted 27 December 2017, 3:55 pm EST

    Hi,

    I could not replicate the issue at my end after creating a similar sample application with the List. Find the sample application attached.

    Also, try to use the latest build which can be downloaded from the link below:

    http://prerelease.componentone.com/dotnet40/C1WPFLibrary/2017-T3/C1WPFBasicLibrary.4_4.0.20173.580.zip

    If this does not solve your issue then share a small sample application with us so that we can assist you further accordingly.

    Thanks,

    Singh

    ReportTest.zip

  • Posted 29 December 2017, 3:07 am EST

    Thank you for your response. Your example proved to me that the List would work and gave me an idea. So I went back and looked at my models that Entity Framework creates and I believe that the related entities are causing the error (I will research later). I created two new models for the reports that only contained the fields that the report needs and changed the function to this and everything works as expected.

    
     public C1FlexReport BuildSubReport2()
            {
                // example using recordset
                C1FlexReport report = new C1FlexReport();
                List<report_client> clients;
                List<report_parcel> parcels;
                using (ClientContext context = new C1Report_Example.ClientContext())
                {
                    clients = context.CLIENT1
                                .Where(a => a.ID.StartsWith("BB"))
                                .Select(s=>new report_client
                                {
                                    ID = s.ID,
                                    COMPANY = s.COMPANY
                                }).ToList();
                    parcels = context.Parcel
                                 .Where(a => a.ID.StartsWith("BB"))
                                 .Select(s=> new report_parcel
                                 {
                                     ID = s.ID,
                                     PARCNUM=s.PARCNUM,
                                     COUNTY=s.COUNTY,
                                     OWNER=s.OWNER
                                 }).ToList();
                }
    
                report.Load("TestReports.flxr", "TestReport1");
                report.DataSource.Recordset = clients;
    
                SubreportField field = (SubreportField)report.Fields["Field1"];
                C1FlexReport subReport = field.Subreport;
    
                subReport.DataSource.Recordset = parcels;
                //report.Render();
                //report.Print();
                return report;
            }
    
    
  • Posted 29 December 2017, 4:39 am EST

    Doing more research, I have found that my POCO’s have Nullable. For example the parcel entity has

    
    public int ParcelId { get; set; }
            public string ID { get; set; }
            public string COUNTY { get; set; }
            public string PARCNUM { get; set; }
            public Nullable<bool> ChildAcct { get; set; }
            public string OWNER { get; set; }
    
    

    changing this from Nullable to plain bool and setting the value to false when null will allow the report to display correctly. I am guessing that the report is handling the entity class differently than a datarow with a nullable value.

  • Posted 1 January 2018, 6:35 pm EST

    Hi,

    I escalated the same to the developer. Will let you know as soon as possible.

    (TFS Id: 303437 for internal use only)

    Thanks,

    Singh

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels