Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Filter Data in a LightSwitch Application by Using Code

By using the <EntitySet>_Filter query method, you can display a subset of records for each user based on permissions. For example, you might want to allow each employee to display only their salary information.

To apply a filter

  1. In Solution Explorer, open the shortcut menu for the entity or table to which you want to apply a filter, and then choose Open.

    The entity or table opens in the Data Designer.

    Note Note

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

  2. On the command bar in the Data Designer, in the Write Code list, choose EntitySet_Filter.

  3. In the Code Editor, add code to the method.

    The following code example filters the Employees entity so that the current user can display only the records that contain their Employee Name:

    partial void Employees_Filter(ref Expression<Func<Employee, bool>> filter)
            {
                  filter = e => e.EmployeeName == this.Application.User.Name;
            }
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.