views:

48

answers:

1

I'm working on a site where we want to include a pie chart on a page. Right now I'm working on implementing that through Reporting Services (RDLC file) with an object data source.

The SelectMethod of my object data source is a method that returns a list of business objects; lets say a List<Alpha> and Alpha has a sub object Beta with a Name property. In my report definition I have set the Category groups to be: =Fields!Beta.Value.Name this means that Alpha.Beta.Name are my pie slices. I got the following error:

  • An error has occurred during report processing. The Group expression for the grouping 'chart1_CategoryGroup1' contains an error: Object variable or With block variable not set.

I was able to confirm this is because Beta is nullable and was able to fix the issue by updating the object Alpha to return a new Beta() if the Beta property is null. This solution is not ideal though because there are other places in my code where I need Beta to be null if it doesn't have a value yet.

Is there a way to update the report definition to accept a null property as valid? Ideally I would like to specify the value as "Not Set" if Beta is null.

A: 

Hello William,

I had similar problem as yours, and I solved it using Null Object Refactoring ( many thanks to Martin Fowler's book Refactoring :)). Here you can find nice example Null object refactoring

So you could create class NullableBeta that inherits Beta, while properties Name and e.g. IsNullable are virtual on Beta entity.

 public class Beta
    {
        public virtual Name{ get; set;}
        public virtual IsSet{ get{return true;}}
    }

    public class NullableBeta:Beta
    {
       public override Name
           { 
             get{
                   return "Not Set";
                }
             set{}
          }
       public override IsSet{ get{ return false;}}
    }

Now, if Beta is not set on Alfa entity, you could return instance of NullableBeta entity. In reports, you would have "Not Set" instead of empty string, and on places where you are setting Beta entity to Alfa you can check IsSet property instead of checking if Beta is null.

Hope this was helpful

Misha N.
Thanks for your help but I googled some different keywords and found this question which handles it the way I wanted. Yours would work but I would need to change my code still to check for "IsSet": http://stackoverflow.com/questions/1343283/how-do-i-handle-null-nested-objects-in-rdlc-report-that-is-bound-to-custom-assemb
William
Ok, solution you found is indeed simpler.
Misha N.