Using LINQ in complex scenarios in SharpShooter Reports

In some cases it is convenient to perform some manipulations with data in code of report scripts. And if you use a framework that supports LINQ you can also use it report scripts.

To do this, you should add the following lines into the list of the assemblies you use (add them as two lines without separators in the Designer, the Document Ribbon tab, the Script group, the «Imports Namespaces» button):


Below you can find a usage example:

Let’s assume we have a list of lines that includes the "One", "Two", "Three", "Four", "Five" values. We want to display all lines except “one” and sort by the line length. It can be easily done using the following code:
// First, we need to get original data source 
System.Collections.Generic.List<string> data = DataObjects["data"as System.Collections.Generic.List<string>;
// Now we need to filter it and sort 
var sortedData = data.Where(t => t != "One").OrderBy(t => t.Length).ToList();
// Finally, we need to add it to the data sources collection and 
// set it as data band's data source name. 
dataBand1.DataSource = "orderedData";
DataObjects.Add("orderedData", sortedData);
Please note that this example also demonstrates how to register a newly-created object in data sources collection.

Add Feedback