Search code examples
visual-studio-2013visual-studio-lightswitchlightswitch-2013lightswitch-2012

Display Distinct values in LightSwitch browse screen


i have one browse screen which is fetching value from one entity(Attached to SQL datasource), the entity will look like the below snapshot. enter image description here

So in the browse screen its coming with all row values (1,2,3 and 4) even though i removed the Role field from the screen. I want to display the distinct Emp ID, Name, Age. Please give me some suggestion.


Solution

  • If you don't have the option of driving your Browse screen from your employee table I'd suggest creating a SQL view similar to the following: -

    CREATE VIEW [dbo].[EmployeeView]
        AS
    SELECT DISTINCT 
        EmpId, 
        Name, 
        Age, 
        Role
    FROM
        dbo.YourTable
    

    You can then attach to the view in LightSwitch and base the Browse screen on the attached view.

    However, please bear in mind that you will only be able to view and not update the information as this type of view uses the DISTINCT clause.

    The following blog post provides some basic details of using views in LightSwitch: -

    Attaching to SQL Views