Search code examples
visual-studio-lightswitchlightswitch-2013

How to delete all table rows in a LightSwitch Application


I am new to the LightSwitch framework and I have to delete all of the data from a table before importing data from csv file into the table.

How do I achieve this?


Solution

  • There's an example of doing that on social.msdn which I'll precis here in case of link rot. It works directly on the Data Workspace to avoid the issue of only the current page of a visual collection being "available" unless you mess with the paging in code. Assuming the entity type is ZoneRate,

        Private Sub Method_Execute()
            For Each zoneRate In Me.DataWorkspace.ApplicationData.ZoneRates
                CType(zoneRate, ZoneRate).Delete()
            Next
            Me.DataWorkspace.ApplicationData.SaveChanges()
        End Sub