Renaming data column / business object property

Stimulsoft Reports.NET discussion
Post Reply
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

Renaming data column / business object property

Post by Tobias »

Is there an easy way to rename data columns and business object properties and all there usages in a *.mrt file (by code, not manually)?

e.g. having a BO:

Code: Select all

class Foo
{
   string FooNumber {get; set;}
   string FooName {get; set;}
}
...
report.RegBusinessObject("Foo", new Foo{..});
...
I now want to rename Foo into Bar and FooNumber/FooName into BarNumber/BarName without the need to manually open the *.mrt in the designer and replace all usages ("{Foo.FooNumber}" and so on).
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Renaming data column / business object property

Post by HighAley »

Hello.

You could use next code to change names of properties:

Code: Select all

            report.RegBusinessObject("Foo", new Foo{FooNumber = "1", FooName = "Name"});
            report.Dictionary.SynchronizeBusinessObjects();
            report.Dictionary.BusinessObjects["Foo"].Columns["FooNumber"].Name = "BarNumber";
            report.Dictionary.BusinessObjects["Foo"].Columns["FooNumber"].NameInSource = "FooNumber";
Thank you.
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

Re: Renaming data column / business object property

Post by Tobias »

Ok thanks.
But I think Name and NameInSource must be switched in your solution to make this work. But it's not exactly what I had in mind. I really need to change the Name of a column, not just the "NameInSource". I hoped there migth by some kind of parser hidden somewhere in the API which allows me to take the mrt and simply replace all the column references or to simply iterate over all column refernces and change them.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Renaming data column / business object property

Post by Alex K. »

Hello,

Unfortunately, there is no a simple solution.
As a way, you can open template report as text file and use string.Replace

Thank you.
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

Re: Renaming data column / business object property

Post by Tobias »

Ok, thanks! I'll probably use XMLReader and search/replace all column references.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Renaming data column / business object property

Post by Alex K. »

Hello,

Ok.
Let us know if you need any additional help.

Thank you.
Post Reply