Console
The DynamicSelect sample demonstrates how to retrieve a table from an instance of Relativity Server where the fields retrieved are limited to those that are needed rather than returning all of them.
Getting Started
The sample is typically located in C:\Users\Public\Documents\RemObjects Samples\Data Abstract for .NET\C#\DynamicSelect (Console)
, though you may have installed the Data Abstract for .NET SDK and it's samples in another location.
To build it, you will of course need Visual Studio, and like all the samples provided with Data Abstract for .NET you will need to be running Relativity Server with the DASamples
Domain and the Simple
Schema available.
Included with the sample is a DataTableExtension
class which has a single public static method (LogToString
) that takes a DataTable
object and creates a nicely formatted string representation of the table that can be printed to the Console which can be useful for debugging purposes. (An example of its output can be seen at the end of this document)
Running the Sample
When run the sample sets up a connection to an instance of Relativity Server and logs in (Step 1). It then creates an array of the names of the fields that are required from the "Clients" table, and then retrieves all of the table rows and prints the table to the console (Step 2).
Examining the Code
All of the code can be found in the Program
source file. The "Clients
" schema table used in this sample has 10 fields, which this sample will limit to just three.
Retrieving data using Dynamic Select (Step 2)
The first step to using Dynamic Select is to create an instance of TableRequestInfoV5 which provides a means to specify custom parameters that will be used when retrieving data from a schema table. The TableRequestInfoV5 class extends the TableRequestInfo class adding in support for Dynamic Select and Dynamic Where.
Then create a String
array that contains the names of the fields that you want to be returned, and then pass that array to the DynamicSelectFieldNames property of TableRequestInfoV5.
The last step is to enable Dynamic Select on the RemoteDataAdapter, by passing true
to the DynamicSelect property.
Now to retrieve the data, use the Fill method of RemoteDataAdapter passing in the DataTable
object that will contain the table data, the previously created TableRequestInfoV5 which contains the names of the required fields, and boolean to apply the schema.
Console.WriteLine("STEP 2: Retrieving data using Dynamic Select");
RemObjects.DataAbstract.Server.TableRequestInfoV5 lRequestInfo = new RemObjects.DataAbstract.Server.TableRequestInfoV5();
lRequestInfo.MaxRecords = -1; // no limits - return all records
lRequestInfo.IncludeSchema = true; // update schema in the result data table to match recieved data (not necessarily).
// Array of field names to select - this is DynamicSelect feature itself.
String[] lDynamicSelect = new String[] { "ClientId", "ClientName", "ClientPhone" };
Console.WriteLine("DynamicSelect is: {0}", String.Join(", ", lDynamicSelect));
lRequestInfo.DynamicSelectFieldNames = lDynamicSelect;
// And finally enable Dynamic Select feature at DataAdapter level
lDataAdapter.DynamicSelect = true;
Console.WriteLine("DynamicSelect feature has been enabled.");
DataTable lTable = new DataTable("Clients");
Boolean lApplySchema = true;
lDataAdapter.Fill(lTable, lRequestInfo, lApplySchema);
Console.WriteLine("STEP 2: Retrieving data using Dynamic Select")
var lRequestInfo: RemObjects.DataAbstract.Server.TableRequestInfoV5! = RemObjects.DataAbstract.Server.TableRequestInfoV5()
lRequestInfo.MaxRecords = -1
// no limits - return all records
lRequestInfo.IncludeSchema = true
// update schema in the result data table to match recieved data (not necessarily).
// Array of field names to select - this is DynamicSelect feature itself.
var lDynamicSelect: String![] = (["ClientId", "ClientName", "ClientPhone"] as? String![])
Console.WriteLine("DynamicSelect is: {0}", String.Join(", ", lDynamicSelect))
lRequestInfo.DynamicSelectFieldNames = lDynamicSelect
// And finally enable Dynamic Select feature at DataAdapter level
lDataAdapter.DynamicSelect = true
Console.WriteLine("DynamicSelect feature has been enabled.")
var lTable: DataTable! = DataTable("Clients")
var lApplySchema: Boolean! = true
lDataAdapter.Fill(lTable, lRequestInfo, lApplySchema)
Example Output
This is an example of the output you will see when the sample is run. You can see in Step 2 that the printed table only contains the specified fields, the other fields were simply not passed to the program.
Dynamic Select sample has been started.
Target URL is http://localhost:7099/bin
RO SDK layer is configured.
RO DataAbstract layer is configured.
STEP 1: Login to DataService
Login string is User Id="simple";Password="simple";Domain="DASamples";Schema="Simple"
Login has been successful. Going further...
STEP 2: Retrieving data using Dynamic Select
DynamicSelect is: ClientId, ClientName, ClientPhone
DynamicSelect feature has been enabled.
Data has been retrieved. Table: Clients; columns count: 3
Table: Clients (7 rows from 7)
|------------------------------------------------------|
| ClientId | ClientName | ClientPhone |
|------------------------------------------------------|
| 18 | Brian L. Rowles | (908) 385-7809 |
| 19 | Angela W. Vanover | (610) 463-9999 |
| 20 | Anna H. Kugler | (817) 249-9525 |
| 21 | Randy R. Howard | (234) 567-8909 |
| 22 | Kenny S. Lay | (817) 249-9525 |
| 23 | Maryann C. Bac... | (907) 722-6777 |
| 24 | Lillie R. Schr... | (312) 476-1404 |
|------------------------------------------------------|
DONE! Please press return to exit.