DataTable.ToDictionary

Overview

Returns a DataTableDictionary by specified columns as key value to fast accessing.

DataTableDictionary myDataTable.ToDictionary(columns: string, separator: string)

Arguments

string columns

Comma or semicolon separated column names. If not specified error is thrown.

string separator

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.

Example

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");

Example

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");

Copyright © 2010 - 2023 Emakin. All rights reserved.