Wednesday, April 18, 2012

Using the summary property of a table to make records more readable

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.

image

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

image

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.

  1. To add a computed property:
    1. In the BillOfMaterials design, click on the computed property button
      image
    2. Rename property1 to ProductComponent and then click on the Edit method link in the property panel.
      image
    3. Add the line result = Product.name in the Compute method
      partial void ProductComponent_Compute(ref string result)
      {
          // Set result to the desired field value
          if (Product != null)
              result = Product.Name;
      }

  2. To set the computed property as the summary property


    1. Select ‘BillOfMaterial’ in the properties panel choice list (or click on the title BillOfMaterial) in the design window.

    2. Change the summary property to ProductComponent.
      image

  3. To prove everything works as expected, create a List and Details screen


    1. In solution Explorer, Right click on the Screens folder, Add screen

    2. 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.
      image

  4. Build and debug the app. The List panel will display the name of the product instead of the Unit Measure code.
    image










Remark


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.

3 comments:

Unknown said...

louis vuitton outlet, sac longchamp, ralph lauren pas cher, replica watches, louboutin outlet, louboutin shoes, christian louboutin outlet, prada outlet, ugg boots, longchamp pas cher, tiffany and co, louis vuitton, louboutin, air jordan pas cher, tory burch outlet, cheap oakley sunglasses, nike outlet, polo ralph lauren outlet, ray ban sunglasses, polo ralph lauren outlet, louis vuitton outlet, nike air max, replica watches, louis vuitton, air max, longchamp outlet, michael kors, oakley sunglasses, chanel handbags, nike free, nike roshe run, oakley sunglasses, burberry, tiffany jewelry, ray ban sunglasses, kate spade outlet, prada handbags, oakley sunglasses, nike air max, louis vuitton, louboutin pas cher, uggs on sale, ray ban sunglasses, oakley sunglasses, longchamp, jordan shoes, gucci outlet, ugg boots, nike free, longchamp outlet

Unknown said...

lancel, celine handbags, jimmy choo shoes, bottega veneta, nike roshe, asics running shoes, gucci, giuseppe zanotti, nike huarache, mcm handbags, herve leger, hollister, hollister, new balance, ray ban, p90x workout, soccer shoes, babyliss, longchamp, mac cosmetics, nike trainers, chi flat iron, mont blanc, vans, vans shoes, ghd, iphone cases, nike air max, hollister, ferragamo shoes, ralph lauren, louboutin, nike air max, beats by dre, valentino shoes, converse outlet, lululemon, north face outlet, instyler, soccer jerseys, birkin bag, insanity workout, baseball bats, north face outlet, abercrombie and fitch, timberland boots, reebok shoes, nfl jerseys, oakley, wedding dresses

Unknown said...

hollister, louis vuitton, canada goose outlet, moncler, pandora jewelry, swarovski, louis vuitton, bottes ugg, coach outlet, moncler, supra shoes, montre pas cher, moncler, ugg,uggs,uggs canada, ugg,ugg australia,ugg italia, canada goose, links of london, pandora jewelry, karen millen, doudoune canada goose, juicy couture outlet, moncler, pandora charms, marc jacobs, swarovski crystal, moncler, ugg pas cher, thomas sabo, louis vuitton, moncler outlet, moncler, canada goose, canada goose uk, canada goose outlet, ugg boots uk, juicy couture outlet, wedding dresses, moncler, canada goose, toms shoes, louis vuitton, replica watches, sac louis vuitton pas cher, pandora charms, canada goose