Converting Business Object

Stimulsoft Reports.BLAZOR discussion
Post Reply
admin@secsol.co.uk
Posts: 34
Joined: Wed Jun 01, 2022 8:26 am

Converting Business Object

Post by admin@secsol.co.uk »

HI,

I have a BusinessObject in my data sources and in a user defined function (C#) I am trying to convert the business object back to its original type using this code :

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.EstimateSection> FullSectionList = SelectedEstimate.FullSectionList as System.Collections.ObjectModel.Collection<Cypher1.EstimateSection>;
but I get the following error saying that the BusinessObject cannot be converted to a Collection<>
The error of compilation is found in the 'Schedule Of Rates Detailed' report: Compilation error: Cannot convert type 'Reports.Report.SelectedEstimateBusinessObject.FullSectionListBusinessObject' to 'System.Collections.ObjectModel.Collection' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
What have I done wrong?
Lech Kulikowski
Posts: 7332
Joined: Tue Mar 20, 2018 5:34 am

Re: Converting Business Object

Post by Lech Kulikowski »

Hello,

Please send us a sample that reproduces the issue for analysis.

Thank you.
admin@secsol.co.uk
Posts: 34
Joined: Wed Jun 01, 2022 8:26 am

Re: Converting Business Object

Post by admin@secsol.co.uk »

Hi, I have attached a sample project that shows the problem.

If you run the program and load the Report.mrt file then click the Preview you will see the error.
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Converting Business Object

Post by Max Shamanov »

Hello,

We require more time to investigate the issue thoroughly.

Thank you.
#15849
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Converting Business Object

Post by Max Shamanov »

Hello,

Please use the following code for a custom function:

Code: Select all

TestItem SelectedItem = null;

System.Collections.ObjectModel.Collection<TestItem> TestItemList = TestList.Current as System.Collections.ObjectModel.Collection<TestItem>;

foreach(TestItem TItem in TestItemList)
{
  if(TItem.Recno == recno)
  {
    SelectedItem = TItem;
    break;
  }
}

return SelectedItem;
Thank you.
admin@secsol.co.uk
Posts: 34
Joined: Wed Jun 01, 2022 8:26 am

Re: Converting Business Object

Post by admin@secsol.co.uk »

Thank you, that works perfectly.
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Converting Business Object

Post by Max Shamanov »

Hello,

You are Welcome!
Post Reply