How to: Define Data Fields in a LightSwitch Database


For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

You can add fields to an entity or a table in the LightSwitch database and modify the appearance and behavior of these fields.

This topic contains the following sections:

link to video For a related video demonstration, see How Do I: Format Data on a Screen in a LightSwitch Application?.

You can add fields to a table. In an entity that's generated from an external data source, you can add computed fields only.

See How to: Add a Computed Field.

To add a data field

  1. In Solution Explorer, open the shortcut menu for an entity or table, and then choose Open.

    System_CAPS_ICON_note.jpg Note

    For applications that have been upgraded to Visual Studio 2012 Update 2, on the Perspective bar, choose the Server tab.

    The entity or table opens in the Data Designer.

  2. In the Name column, enter a name for the field.

  3. In Type column, choose a data type for the new field. The following table describes each type.

    TypeVisual Basic TypeC# TypeRangeRemarks
    BinaryByte()byte[]-128 to 127.An array of bytes that has a variable length.
    BooleanBooleanboolTrue or false.
    DateDateTimeDateTimeA DateTime that's treated as a date only.
    DateTimeDateTimeDateTime12:00:00 AM, Jan 1, 0001 through 11:59:59 PM, Dec 31, 9999.
    DateTimeOffsetDateTimeDateTimeA value that represents a date and time in Coordinated Universal Time (UTC) format.
    DecimalDecimaldecimal±1.0 × 10<sup>−28</sup> to ±7.9 × 10<sup>28</sup>.A fixed decimal point with 28-29 significant digits; good for accounting numbers.
    DoubleDoubledouble±5.0e−324 to ±1.7e308.A floating decimal point with 15-16 digits precision; good for scientific numbers.
    Email AddressStringstringA string that's treated as an email address.
    GuidStringstringA string that's formatted as a globally unique identifier (GUID). The value is automatically generated for each record.
    ImageByte()Byte[]A binary that's treated as an image.
    Short IntegerShortshort-32,768 to 32,767.A signed 16-bit integer.
    IntegerIntegerint-2147483647 to 2147483647.A signed 32-bit integer.
    Long IntegerLonglong-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.A signed 64-bit integer.
    MoneyDecimaldecimalA decimal that's treated as a monetary value.
    PercentDecimaldecimalA decimal that's treated as a percentage.
    PersonStringStringA string that’s treated as a user identity.
    Phone NumberStringstringA string that's treated as a phone number.
    StringStringstringA sequence of zero or more Unicode characters that has a variable length.
    Web AddressStringstringA string that's treated as a web address (URL).
  4. If you want to require users to provide a value for this field, select the Required check box.

You can modify a field by editing its properties in the Properties window.

If the entity was generated from an external data source, you won't be able to edit some field properties because they reflect configuration settings of the data source.

You can't override those settings by changing field properties. You must make changes to these fields on the server and then import those changes into LightSwitch by refreshing the data source.

To modify a field

  1. In the Data Designer, choose the field that you want to modify.

  2. In the Properties window, set property values.

    See Reference: Data Designer Properties.

Data: The Information Behind Your Application
How to: Validate Data
How to: Create a List of Values for a Field
How to: Add a Computed Field