Retrieve a Record
The following example shows how to retrieve (or "select") a record by reference:
Record selected = docs.SelectOne( docs.Column("Reference") == @"C:\data\file1.txt", new string[] { "Reference", "LastModified"});
The first argument specifies the query to perform and selects records where the Reference column is equal to "C:\data\file1.txt
". The query is expressed in terms of a filter - of all the records, only those that match the filter are selected. The second argument specifies the columns to retrieve.
You can extract the values from the Record
object using the square brackets operator or one of the GetAs
methods for common types:
string reference = selected["Reference"]; DateTime lastModified = selected.GetAsDateTime("LastModified");
The SelectOne
method returns the first record to match the filter, or null
if no records match. To retrieve more than the first match you can use the Select
method instead.
Retrieve Multiple Records
To retrieve multiple records, use the Select
function:
docs.Select( record => task.Log.WriteLine(LogLevel.Normal, "Found record: " + record["Reference"]), docs.Column("Reference") == @"C:\data\file1.txt", new string[] { "Reference", "LastModified" });
The second and third arguments are identical to those of the SelectOne
method. They specify a filter and the columns to return. The first argument specifies a function that is called for each record found, which in this case writes the reference to the log.