Specifying a Computed Property on Entities in Table Using LightSwitch 2012

This article describes how to specify a Computed Property on Table Entities in LightSwitch using Visual Studio 2012.

The following is the procedure for specifying a Computed Property on Table Entities.

Step 1

Open the Solution Explorer.

sol explo.jpg

Step 2

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

add table.jpg

Step 3

The Table appears.

tab.jpg

Step 4

From the table, suppose we select the Name entity (property). We can add a computed property by clicking at the top of the Computed Property button.

property win.jpg

We can also add this property by marking the "Is Computed" Checkbox as checked.

computed prop.jpg

This sets the "Is Computed" property in the properties window for you.

Step 5

In the Property window click on the "Edit Method" link.

property win.jpg

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.LightSwitch;

namespace LightSwitchApplication

{

    public partial class Employee

    {

        partial void Name_Compute(ref string result)

        {

            // Set result to the desired field value

            result = this.FName + " " + this.LName;

 

        }

    }

}

Step 6

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

add src.jpg

Step 7

Select the Add New Screen from the Screen Template. Under Screen Information we provide the Screen Name and Screen Data and then click "OK".

src.jpg

Step 8

The Screen Designer appears.

app designer.jpg

Step 9

Press F5 to run the application.

output2 fill.jpg

Click on the "Save" button and we get:

output correct.jpg


Similar Articles