DataTable.ToDictionary
Overview¶
DataTableDictionary DataTable.ToDictionary ( columns, [ seperator = '.' ] )
Arguments¶
String columns Comma or semicolon separated column names. If not specified error is thrown.
String seperator Separator to use as dictionary key when multiple columns specified. If not specified "." value is used by default.
Remarks¶
- When columns argument contains an invalid column which is not in DataTable error is thrown.
- If multiple columns shares same key, dictionary value would be array of data table row.
Examples¶
Convert users to a dictionary
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
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");