Desktop
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
, 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.
Running the Sample
When run the sample retrieves all of the records from the "Clients" table of the "Simple" schema. However rather than including all of the fields in a row, Dynamic Select is used to specify the fields the fields that should be returned.
The UI is comprised of a table that displays the data, and a toolbar that has a combo box for the server address and three buttons. "Fill" will retrieve the data from the server; you will only need this if you start Relativity Server after you start the sample as the sample will attempt to automatically retrieve the data. "Delete" will delete the currently selected row. Finally "Apply Changes" will send any changes to the local data back to the server.
Double clicking on a field allows you to edit the data in that field, and clicking on the row that starts with an "*" allows you to add a new row.
Examining the Code
The sample is comprised of two classes, DataModule which handles the interaction with the server and MainForm that handles the UI interaction. The code discussed below comes from the DataModule class.
The "Clients" table in the "simple" schema, is comprised of 10 fields which the sample filters down to just 6.
Retrieving data using Dynamic Select
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.
public DataTable GetData()
{
DataTable lClientsData = new DataTable("Clients");
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", "ClientEmail", "ClientPassword", "ClientPhone", "ClientAddress" };
lRequestInfo.DynamicSelectFieldNames = lDynamicSelect;
// And finally enable Dynamic Select feature at DataAdapter level
this.DataAdapter.DynamicSelect = true;
this.DataAdapter.Fill(lClientsData, lRequestInfo, true);
return lClientsData;
}
method DataModule.GetData: DataTable;
begin
var lClientsData: DataTable := new DataTable('Clients');
var lRequestInfo: RemObjects.DataAbstract.Server.TableRequestInfoV5 := 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.
var lDynamicSelect: array of String := array of String(['ClientId', 'ClientName', 'ClientEmail', 'ClientPassword', 'ClientPhone', 'ClientAddress']);
lRequestInfo.DynamicSelectFieldNames := lDynamicSelect;
// And finally enable Dynamic Select feature at DataAdapter level
self.DataAdapter.DynamicSelect := true;
self.DataAdapter.Fill(lClientsData, lRequestInfo, true);
exit lClientsData
end;
public func GetData() -> DataTable! {
var lClientsData: DataTable! = DataTable("Clients")
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", "ClientEmail", "ClientPassword", "ClientPhone", "ClientAddress"] as? String![])
lRequestInfo.DynamicSelectFieldNames = lDynamicSelect
// And finally enable Dynamic Select feature at DataAdapter level
self.DataAdapter.DynamicSelect = true
self.DataAdapter.Fill(lClientsData, lRequestInfo, true)
return lClientsData
}
Public Function GetData() As DataTable
Dim lClientsData As New DataTable("Clients")
Dim lRequestInfo As 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.
Dim lDynamicSelect As String() = New String() {"ClientId", "ClientName", "ClientEmail", "ClientPassword", "ClientPhone", "ClientAddress"}
lRequestInfo.DynamicSelectFieldNames = lDynamicSelect
' And finally enable Dynamic Select feature at DataAdapter level
Me.DataAdapter.DynamicSelect = True
Me.DataAdapter.Fill(lClientsData, lRequestInfo, True)
Return lClientsData
End Function
Updating the server with a Delta of changes
In the SimpleDataOperations sample it shows how to apply local changes to the server by passing a DataSet
to the Update method of RemoteDataAdapter. The issue with that version of the method is that ALL changes to every table in the DataSet
will be updated on the server.
If you want to only update a particular table(s) you can instead use an alternative version of Update that takes an array of Delta change objects, each of which contain the changes for a particular table. The Delta object can be quickly constructed by passing it a DataTable
that contains changes.
public void UpdateData(DataTable table)
{
Delta changes = new Delta(table);
this.DataAdapter.Update(new Delta[] { changes });
}
method DataModule.UpdateData(table: DataTable);
begin
var changes: Delta := new Delta(table);
self.DataAdapter.Update(array of Delta([changes]))
end;
public func UpdateData(table: DataTable!) {
var changes: Delta! = Delta(table)
self.DataAdapter.Update(([changes] as? Delta![]))
}
Public Sub UpdateData(table As DataTable)
Dim changes As New Delta(table)
Me.DataAdapter.Update(New Delta() {changes})
End Sub