child objects in rdlc (Studio 2010RC)

后端 未结 3 608
萌比男神i
萌比男神i 2020-12-09 20:28

I am attempting to reference a sub-object in a field expression in a studio 2010 report. This used to work in prior versions. When account references another object with pro

相关标签:
3条回答
  • 2020-12-09 21:01

    This is probably not an appropriate answer, but when I feel like the lack of material on this subject encourage me to post about my findings.

    Let's say If I have a nested list of children object within the parent object. This is a very common situation for example, if you have an order object(parent), you will probably have a list of order items(children), how do you display all the information with the rdlc? There are two ways, 1 using subreport, and 2 is to use grouping. I realize they can both achieve the same thing which is displaying list of details on a report.

    public class Order{
        public int OrderID {get; set;}
        public string Descrpition {get; set;}
        public List<OrderItem> OrderItems {get; set;}
    }
    public class OrderItem{
        public int OrderItemID {get; set;}
        public decimal Price{get; set;}
    }
    

    The easiest way is to use grouping. With grouping, you have to create a new datatype that contains the properties of the parent and children. I believe this way works with multi-level nested list of objects also. It might sound stupid, but most of the time you have to create a new datatype anyway because the types you need to display on the report are different from the business objects:

    public class OrderReport{
        public int OrderID {get; set;}
        public string Description {get; set;}
        public int OrderItemID {get; set;}
        public decimal Price {get; set;}
    }
    

    Then on the rdlc, you just have to create parent row group and a child row group, Parent should be grouped by OrderID, the child row group should be set to "show details". I think you can do this multiple times to achieve multi-level nested list of objects.

    0 讨论(0)
  • 2020-12-09 21:07

    I can confirm that this bug has been fixed in VS2010 SP1 ... but you have to mark all of the relevant classes as Serializable.

    You can find a sample project on this site which shows a working version: http://wraithnath.blogspot.com/2011/04/reportviewer-object-datasource-nested.html

    The author also mentions that your classes will need a parameterless constructor but I have gotten it to work using classes without a default constructor. Still, if you have marked everything as serializable and are still seeing the "#Error" message, give it a try with parameterless constructors.

    0 讨论(0)
  • 2020-12-09 21:13

    Unfortunately you can't (as yet), and the work-around is to create properties in the parent object.

    More info:

    • https://connect.microsoft.com/VisualStudio/feedback/details/553592/accessing-nested-objects-in-data-source-of-local-report-does-not-function
    • http://blogs.msdn.com/b/brianhartman/archive/2010/10/27/nested-objects-in-local-mode.aspx
    0 讨论(0)
提交回复
热议问题