Summary properties are displayed anytime you use the Summary control on a screen or when LightSwitch generates a layout for you that needs to display a description of the entity.
To show the user a better string representation of the records in some tables, we can use a computed column as the summary property of a table. By default summary properties are set to the first string column of an entity. For example whith the BillOfMaterials entity from the AdventureWorks database, the Summary Property will be set to the column UnitMeasureCode.
A nicer representation could be the Assembly product name, the assembly product is linked by a foreing key productassemblyId to the BillOf²Materials table. In the entity it is somewhat awkwardly represented as Product1
First we will add a computed property that displays the name of the product and then we set this computed field as the Summary Property of the entity.
- To add a computed property:
- In the BillOfMaterials design, click on the computed property button
- Rename property1 to ProductComponent and then click on the Edit method link in the property panel.
- Add the line result = Product.name in the Compute method
- To set the computed property as the summary property
- Select ‘BillOfMaterial’ in the properties panel choice list (or click on the title BillOfMaterial) in the design window.
- Change the summary property to ProductComponent.
- To prove everything works as expected, create a List and Details screen
- In solution Explorer, Right click on the Screens folder, Add screen
- In the Add new screen dialog, select screen template ‘List and details screen’, Screen Data: AdventureWorks…BillOfMaterials, additional data to include is checked. Click OK.
- Build and debug the app. The List panel will display the name of the product instead of the Unit Measure code.
The use of computed property columns as summary column has some disadvantage: The computed column can take some time time to calculate and display, You cannot sort on the computed column either. Fancier solutions can be made with WCF RIA data services on the server side.