How to: Define Data Fields in a LightSwitch Database
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:
Adding a Data Field.
Modifying a Field.
For a related video demonstration, see How Do I: Format Data on a Screen in a LightSwitch Application?.
Adding a Data Field
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 in a LightSwitch Database.
To add a data field
In Solution Explorer, open the shortcut menu for an entity or table, and then choose Open.
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.
In the Name column, enter a name for the field.
In Type column, choose a data type for the new field. The following table describes each type.
Type
Visual Basic Type
C# Type
Range
Remarks
Binary
Byte()
byte[]
-128 to 127.
An array of bytes that has a variable length.
Boolean
Boolean
bool
True or false.
Date
DateTime
DateTime
A DateTime that's treated as a date only.
DateTime
DateTime
DateTime
12:00:00 AM, Jan 1, 0001 through 11:59:59 PM, Dec 31, 9999.
DateTimeOffset
DateTime
DateTime
A value that represents a date and time in Coordinated Universal Time (UTC) format.
Decimal
Decimal
decimal
±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.
Double
Double
double
±5.0e−324 to ±1.7e308.
A floating decimal point with 15-16 digits precision; good for scientific numbers.
Email Address
String
string
A string that's treated as an email address.
Guid
String
string
A string that's formatted as a globally unique identifier (GUID). The value is automatically generated for each record.
Image
Byte()
Byte[]
A binary that's treated as an image.
Short Integer
Short
short
-32,768 to 32,767.
A signed 16-bit integer.
Integer
Integer
int
-2147483647 to 2147483647.
A signed 32-bit integer.
Long Integer
Long
long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
A signed 64-bit integer.
Money
Decimal
decimal
A decimal that's treated as a monetary value.
Percent
Decimal
decimal
A decimal that's treated as a percentage.
Person
String
String
A string that’s treated as a user identity.
Phone Number
String
string
A string that's treated as a phone number.
String
String
string
A sequence of zero or more Unicode characters that has a variable length.
Web Address
String
string
A string that's treated as a web address (URL).
If you want to require users to provide a value for this field, select the Required check box.
Modifying a Field
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
In the Data Designer, choose the field that you want to modify.
In the Properties window, set property values.
See Also
Tasks
How to: Validate Data in a LightSwitch Application
How to: Create a List of Values for a Field in a LightSwitch Application
How to: Add a Computed Field in a LightSwitch Database