Customizing Entity Fields

In this lesson, you will learn how to set display properties and change the data type for individual fields in a data entity in LightSwitch.

Customize Entity Fields

Display properties are used to specify how the data for a given field is displayed to the user. For example, you could specify a different display name for a field.

To set field properties

  1. In Solution Explorer, double-click Customers.

    The Data Designer opens. Click the title bar to make sure that the entity itself is selected.

  2. In the Properties window, in the Summary Property list, select CompanyName.

  3. In the Data Designer, select the CompanyName field.

  4. In the Properties window, select the Display Name property and type Company.

    Tip

    Database field names cannot contain spaces and may use an underscore character to represent a space. To assure that displayed field names are user friendly, review the field names in your database entities and change the Display Name property for fields that require a better display name.

  5. Select the ContactName field. In the Properties window, set the Description property to This is our primary contact at this company.

    The value of the Description property is displayed as a tooltip in the application when a user rests the pointer on the field.

Fields in a database table are often stored in a format that is efficient for the database but may not be what you want to display to the user. For example, fields that represent monetary values are typically stored as a Decimal data type, but are typically displayed as currency in an application.

To change data types

  1. In the Data Designer, select the Phone field.

  2. In the Type column, select PhoneNumber on the drop-down list.

    PhoneNumber is a custom business type that displays a telephone number in a standardized format.

  3. In Solution Explorer, double-click Order_Details.

  4. In the Data Designer, select the UnitPrice field.

  5. In the Type column, select Money on the drop-down list.

    Money is another custom business type for formatting and displaying currency values.

Closer Look

This lesson showed how to set properties for entity fields and also how to change the data type of a field. It is a good practice to follow these steps immediately after you add an entity, but you can change properties and data types at any time during application development.

The first property that you set was the Summary property. For screens that contain lists, this field is displayed in the list instead of the default ID field.

Most of the properties that you can set are related to appearance, but others are available to set validation rules and other characteristics. Availability of properties varies by data type. Later lessons describe other properties.

By using a custom data type, you can present data in a way that is most appropriate for your application without changing a type in the underlying database. The Money type demonstrates this principle because it converts the decimal format in the database to a currency format in the display. Not only do you not have to do this work, but the database retains its efficient decimal format. Many custom data types provide type-specific properties, for example, the Symbol Mode property for the Money type that determines how a currency symbol is displayed.

In addition to the PhoneNumber and Money custom business types, LightSwitch also provides the EmailAddress and Image types. Additional custom business types can be added as extensions. Another lesson will show how to obtain extensions.

Note

Images are often stored in a database as a Binary data type. You cannot display a Binary type, but you can change it to the Image type for display purposes.

Next Steps

In the next lesson you will learn how to present a list of predetermined values to the user. Next lesson: Presenting a List of Choices

See Also

Tasks

How to: Define Data Fields

How to: Validate Data

Other Resources

Working with Data in LightSwitch (Guided Tour)

Extensions: Adding New Capabilities to LightSwitch