The query builder allows use to write LINQ-like queries within query { ... }
code blocks. The F# LINQ expressions have all the functions defined in the QueryBuilder
class. We can also define our own query builder and use the CustomOperation
attribute to define new LINQ operations. The need to build a custom query builder is required when we have a new set of functions that is not available in the existing QueryBuilder
class, or if we want to have custom functions for data collections.
In this section, we will learn how to create a custom sequence builder to reuse the Seq
module as LINQ query expressions. The query expression needs to satisfy three preconditions, which are as follows:
For
: This is the method used to support the F# query syntax. It projects each element of a sequence to another sequence and combines the resulting sequences into one.Yield
: This returns a sequence of length, one which contains the specified value.Zero
: This returns an empty sequence of the given...