Customizing Entity Fields in LightSwitch
In this lesson, you’ll learn how to set display properties and change the data type for individual fields in a data entity in LightSwitch.
By using display properties, you specify how the data for a given field appears to the user. For example, you could specify a different display name for a field.
To set field properties
In Solution Explorer, open the shortcut menu for the Customers.lsml node, and then choose Open.
The Data Designer opens.
On the Perspective bar, choose the DesktopClient tab.
In the Properties window, in the Summary Property list, choose CompanyName.
In the Data Designer, choose the CompanyName field.
In the Properties window, choose the Display Name property, then and enter Company in the text box.
Database field names can’t contain spaces and may use an underscore character to represent a space. To ensure that displayed field names are user friendly, review the field names in your database entities, and change the Display Name property for any fields that require a better display name.
In the Description property for the ContactName field, enter This is our primary contact at this company.
The value of the Description property appears as a tooltip in the application when a user points to a field.
Fields in a database table are often stored in a format that's 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 they typically appear as currency in an application.
To change data types
In the Data Designer, on the Perspective bar, choose the Server tab.
In the Customer table, choose the Phone field.
In the Type column, open the list, and then choose PhoneNumber.
PhoneNumber is a custom business type that displays a telephone number in a standardized format.
In Solution Explorer, open the shortcut menu for the Order_Details node, and then choose Open.
In the Data Designer, choose the UnitPrice field.
In the Type column, open the list, and then choose Money.
Money is another custom business type for formatting and displaying currency values.
This lesson showed how to set properties for entity fields and also how to change the data type of a field. It's 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 appears 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's most appropriate for your application without changing a type in the underlying database. The Money type demonstrates this principle by converting the decimal format in the database to a currency format in the display. Not only don't you have to do this work, but also 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 determines how a currency symbol appears.
In addition to the PhoneNumber and Money custom business types, LightSwitch also provides the EmailAddress, Hyperlink, Percentage, Web Address, and Image types. You can also add other custom business types as extensions, as another lesson will show.
Images are often stored in a database as a Binary data type. You can't display a Binary type, but you can change it to the Image type for display purposes.
In the next lesson, you’ll learn how to present a list of predetermined values to the user. Next lesson: Presenting a List of Choices in a LightSwitch Application