Rdlc: reporting off a child object that is an IList of some primitive type

rdlc

I am using rdlc reports to report off some businesss objects.
I use subreports to report off of nested objects (as described here).

When using a regular list of child objects, like IList(Of Books), I create a datasource for books, and then use this as the datasource of the subreport.

I'm little stuck how to use this technique when the nested object is an IList(Of String), or another list of a primitive type.

What's the best way to do the reporting in this scenario?

Best Answer

I encountered a similar problem. I had a report running of a list of CustomObject. The CustomObject list was populated from a query on a list of ParentObjects that contained many-many references to all their CustomObjects. The relationship was removed and a string column was used on the ParentObject (ParentObject.CustomObjectName) instead. Now my report receives a string[] containing all the CustomObject names.

My solution was creating a wrapper object with a single string property and a constructor to use as my data source. I named it just like the CustomObject my report was expecting.

class CustomObject 
{ 
   public string Name {get; set;} 

   public CustomObject(string name)
   {
      Name = name;
   }
}

I load my list using LINQ, I call the wrapper constructor in the select statement

var wrappedObjects = from parent in GetParentObjects()
   select new CustomObject(parent.CustomObjectName);

From the report you can add a data source for the CustomObject class like you normally would and access the object as usual "=Fields!Name.Value".

Related Topic