DataEngine for .NET Standard | ComponentOne
Work with Data Engine / Connect Data Engine / Connect Data Engine to Objects
In This Topic
    Connect Data Engine to Objects
    In This Topic

    With the Data Engine library, you can import data from a collection of objects of a specific class type to the DataEngine table.

    To connect Data Engine to Objects, you need to follow the steps given below:

    1. Initialize a new workspace folder relative to the project root directory using the Init method of the Workspace class.

      // Create and initialize a new workspace folder relative to the project root directory
      Workspace workspace = new Workspace();
      workspace.Init("workspace");
    2. Create a class having a method that returns a collection of the class objects.

      class Employee
      {
          public int EmployeeID { get; set; }
          public string Department { get; set; }
          public double Salary { get; set; }
          public static List<Employee> GetList()
          {
      
              List<Employee> employeeList = new List<Employee>();
              string[] departments = { "Production", "Finance", "HR", "R&D", "Marketing" };
              Random random = new Random();
              for (int i = 0; i < 1000; i++)
              {
                  employeeList.Add(new Employee()
                  {
                      EmployeeID = i + 1,
                      Department = departments[random.Next(0,5)],
                      Salary = Math.Round(random.NextDouble() * 100000, 2),
                  });
              }
              return employeeList;
          }
      }
    3. Retrieve the collection of class objects as shown:

      //Retrieve the collection of objects of the specific class type 
      List<Employee> employeeList = Employee.GetList();
    4. To connect DataEngine to the retrieved collection of custom objects, create an instance of the ObjectConnector class and pass the Workspace object and the custom collection initialized above as parameters to its constructor. Use the GetData method of the ObjectConnector class to create a DataEngine base table containing the imported data.

      //Import data from the custom collection to a DataEngine table
      ObjectConnector<Employee> connector = new ObjectConnector<Employee>(workspace, employeeList);
      connector.GetData("Employees");

      Once the connection is established, the queries can be defined and executed to fetch the desired data. Refer to Transform Data topic for more information.