Computed Property in LightSwitch 2012

Here we will see how to use the Computed Property in a LightSwitch Application (Visual C#) in Visual Studio 2012.

The following is the procedure for using the Computed Property in LightSwitch.

Step 1

Open the Solution Explorer.

sol ex.jpg

Step 2

In the Solution Explorer, right-click on the Server and choose "Add Table".

add tab.jpg

Step 3

The table appears.

emp.jpg

Step 4

In the table designer go to the menu bar and choose "Computed Property".

computed prop.jpg

Once you click on it, a column is added as Property1 to the table.

property.jpg

We can easily change the name of the column by clicking on it and renaming it, as well as change the data type.

Employee.jpg

Step 5

Select the Computed Property column and go to the property window and click on the "Edit Method" link as shown.

prop win.jpg

Step 6

The Code Designer appears.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.LightSwitch;

namespace LightSwitchApplication

{

    public partial class Employee

    {

        partial void IsEligibleToWork_Compute(ref bool result)

        {

            // Set result to the desired field value

            if (Age < 60)

            {

                result = true;

            }

            else

            {

                result = false;

            }

        }

    }

}

Step 7

In the Solution Explorer, right-click on the Screens and choose "Add Screen".

Add Src.jpg

Step 8

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, under screen information, choose "Employee" under the screen data and provide a name to the Screen and click the "OK" button.

Add New Src.jpg

Step 9

The Screen Designer appears.

Step 10

Press F5 once again to run the application.

output1.jpg


Similar Articles