DataTable ToDictionary Returns a DataTableDictionary indexed by the specified columns for fast access.
myDataTable.ToDictionary(columns: string, separator: string):DataTableDictionary
Parameters string columns A comma-separated or semicolon-separated string of column names to use as the key. If not specified, an error is thrown.
string separator The separator to use for the dictionary key when multiple columns are specified. If not specified, a "." (dot) is used by default.
Returns A DataTableDictionary instance.
When the columns
argument contains an invalid column that is not in the DataTable , an error is thrown. If multiple rows share the same key, the dictionary value will be an array of data table rows.
Convert users to a dictionary: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 var employeeTable = $Database . Get ({
Parameters : {
TargetSchema : 'HR' ,
TargetTable : 'Employee'
}
});
var employeeList = employeeTable . ToDictionary ( 'RegistryNumber' );
// employeeList now contains
// {
// "1234" : { Id : "ABC", RegistryNumber: "1234", StartDate: ... }
// "4567" : { Id : "DEF", RegistryNumber: "4567", StartDate: ... }
// }
var employee = employeeList . Get ( "12345" );
Using multiple columns: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 var employeeTable = $Database . Get ({
Parameters : {
TargetSchema : 'HR' ,
TargetTable : 'Employee'
}
});
var employeeList = employeeTable . ToDictionary ( 'Id,RegistryNumber' );
// employeeList now contains
// {
// "ABC.1234" : { Id : "ABC", RegistryNumber: "1234", StartDate: ... }
// "DEF.4567" : { Id : "DEF", RegistryNumber: "4567", StartDate: ... }
// }
var employee = employeeList . Get ( "ABC.1234" );
See Also