child objects in rdlc (Studio 2010RC)

后端 未结 3 615
萌比男神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 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.

提交回复
热议问题