Friday, June 16, 2017

Lambda expression, it's an anonymous function it can use to create delegates or expression tree, by using lambda conditions, we can write local functions that can be passed as parameters. Let's see it in action for deleting a records using Lambda expression for Where and While condition in Managed Dbf and it's equivalent xBase/Clipper/Vfp code.

TASK : Delete all customers from USA country and state of New York or California.

.

Solution 1 : ( Slowest )

This is the slowest solution, iterating to all records and check if we meet the condition criteria before

marking the record for deletion.

Equivalent xBase/Clipper/VFP commands :

.

Solution 2 : ( Slow )

This is slow but not the slowest solution, any method using *All in Managed Dbf are using disk caching for reading all records and this solution is only using single line of code and lambda expression condition for deleting a record.

Equivalent xBase/Clipper/Vfp commands :

.

Solution 3 : ( Fast )

This is a fast solution because it uses index file to searching country and continue reading WHILE the country still match the search and test for state conditions before marking the record for deletion.

Equivalent xBase/Clipper/Vfp commands :

.

Solution 4 : ( Fastest )

This is a fastest solution because it uses index file for searching country+state and continue reading WHILE the search condition is true before marking the record for deletion.