Performance of the LightSwitch HTML Client's Tables_SingleOrDefault and Tables.filter operations

168 views Asked by At

We're working with the Visual Studio 2013 version of LightSwitch, and have a number of areas in our HTML Client screens where we've used the following approach to retrieve an entity with a specific id: -

myapp.activeDataWorkspace.ApplicationData.Tables.filter("Id eq " + msls._toODataString(idToFind, ":Int32")).execute()

As we're interested in improving the performance of these screens, I wondered if anyone knows if the following alternative approach would make any difference to the speed? : -

myapp.activeDataWorkspace.ApplicationData.Tables_SingleOrDefault(idToFind).execute()

Whilst the second approach seems more appropriate in this type of situation, as we've a significant number of the former method, I wanted to quantify the value of this change before initiating it (and the re-testing this would entail).

2

There are 2 answers

0
Kris On

Both approaches will produce SQL and execute it on the server. The SQL should be similar/identical and performance will be near identical. If you want to see the SQL being produced i suggest you open up the "SQL Server Profiler" and run a Trace! The trace will also show you execution time taken. Side note: Your performance gains will come from correctly configured Table Indexes.

0
Mohammad Shraim On

I know its old question but i would like to add some info...

Even both are translated to SQL query and executed on SQL Server, the difference in performance will be related to the way that lightSwitch (oData v3) Generate the statement..

Taking in consideration between the following;

1- select * from Table where colA like ('foo')

2- select * from Table where colA = 'foo' TOP(1)

general if colA is primary Key at the table then SQL will stop searching after the first match on the second if just want to retrieve only one ,, and the equal is better performance...

you can trace the generated link query from each one on file msls-2.5.2.js line 6803 to 6900.