When you use XMLA DataSource, your data is already organized in cubes and each dimension has defined hierarchies. However, that is not the case with FlatData. With FlatData, you can define your own hierarchies for each property that is of some custom class. You can do that both in XAML and in code behind. The following paragraphs show you how to do it.
All hierarchies are defined in the DataSource’s collection HierarchyDescriptors.
<igOlap:FlatDataSource.HierarchyDescriptors>
<igOlap:HierarchyDescriptor SourcePropertyName="Product">
<igOlap:HierarchyDescriptor.LevelDescriptors>
<igOlap:HierarchyLevelDescriptor
LevelName="All products" />
<igOlap:HierarchyLevelDescriptor
LevelName="Product name"
LevelExpressionPath="Name" />
</igOlap:HierarchyDescriptor.LevelDescriptors>
</igOlap:HierarchyDescriptor>
<igOlap:HierarchyDescriptor SourcePropertyName="City">
<igOlap:HierarchyDescriptor.LevelDescriptors>
<igOlap:HierarchyLevelDescriptor
LevelName="All locations" />
<igOlap:HierarchyLevelDescriptor
LevelName="City" LevelExpressionPath="Name" />
</igOlap:HierarchyDescriptor.LevelDescriptors>
</igOlap:HierarchyDescriptor>
</igOlap:FlatDataSource.HierarchyDescriptors>
This sample shows how to define a hierarchy for two of the cube’s properties. The cube is the class specified in the data source as main data holder. You may define as many HierarchyLevelDescriptors as you need. LevelExpressionPath is the property on which to group the data. LevelName will appear in the tree with hierarchies in the data selector.
Currently the only auto-generated hierarchies are for the dimensions of DateTime type.
If you want to do the same thing as above from code behind, your code would look like this:
HierarchyDescriptor<Sale> productHierarchy =
new HierarchyDescriptor<Sale>(p => p.Product);
productHierarchy.AddLevel(p => "All products", "All products");
productHierarchy.AddLevel(p => p.Product.Name, "Product name");
flatDataSource.AddHierarchyDescriptor(productHierarchy);
HierarchyDescriptor<Sale> locationHierarchy =
new HierarchyDescriptor<Sale>(p => p.City);
locationHierarchy.AddLevel(p => "All locations", "All locations");
locationHierarchy.AddLevel(p => p.City, "City");
flatDataSource.AddHierarchyDescriptor(locationHierarchy);
Dim productHierarchy As _
New HierarchyDescriptor(Of Sale)(Function(p) p.Product)
productHierarchy.AddLevel(Function(p) "All products", "All products")
productHierarchy.AddLevel(Function(p) p.Product.Name, "Product name")
flatDataSource.AddHierarchyDescriptor(productHierarchy)
Dim locationHierarchy As _
New HierarchyDescriptor(Of Sale)(Function(p) p.City)
locationHierarchy.AddLevel(Function(p) "All locations", "All locations")
locationHierarchy.AddLevel(Function(p) p.City, "City")
flatDataSource.AddHierarchyDescriptor(locationHierarchy)