# Quick Start

A simple application using DataEngine library in Visual Studio. Users get a chance to try a hand at using the C1DataEngine library in their VS application in few steps.

## Content

This section will help you to get started with the **DataEngine** library:

### Create .NET Core application:

1. Create a new **.Net Core 2.2** console web application.
2. Add the **C1.DataEngine** and **C1.DataEngine.Api** NuGet packages to your application.

### Connect DataEngine to DataSource

1. In the Main method of the **Program.cs** file, add the following code to initialize a new workspace folder relative to the project root directory using the [Init](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.Init.html) method of the [Workspace](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.html) class. 

    ```csharp
    //Initialize a new workspace folder relative to the project root directory
    Workspace workspace = new Workspace();
    workspace.Init("workspace");
    ```
2. Initialize the connection string to the database file, the data of which you wish to import to the **DataEngine** base tables using the following code:

    ```csharp
    public string GetConnectionString()
    {
        string filename = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\ComponentOne Samples\Common\NORTHWND.MDF;";
        return String.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0}; Integrated Security=True;Connect Timeout=30;User Instance=True", filename);
    }
    ```
3. Create **SqlConnection** and **SqlCommand** objects to hold the desired data that needs to be imported.

    ```csharp
    SqlConnection conn = new SqlConnection(GetConnectionString());
    conn.Open();
    var command = new SqlCommand("Select * from Invoices", conn);
    ```
4. Create an instance of the [DbConnector](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.DbConnector.html) class and pass the **Workspace**, **SqlConnection** and **SqlCommand** objects as parameters to its constructor. Use the [GetData](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.DbConnector.GetData.html) method of **DbConnector** class to create a DataEngine table containing the imported data.

    ```csharp
    //Import data from database to a DataEngine table
    var connector = new DbConnector(workspace, conn, command);
    connector.GetData("Invoices");
    ```

### Define and Execute Query

1. Once the **DataEngine** base table is created, retrieve it using the [table](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.table.html) method of [Workspace](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.html) class. Perform desired queries on the data using the [query](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.query.html) method of **Workspace** class.

    ```csharp
    //Retrieve the base table for use in constructing queries
    dynamic invoice = workspace.table("Invoices");
    ```
2. Execute the query by invoking the [Execute](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Query.Execute.html) method of the [Query](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Query.html) class.

    ```csharp
    //Find the total sales by country
    dynamic query = workspace.query("SalesByCountry", new
    {
        invoice.Country,
        Sales = Op.Sum(invoice.ExtendedPrice)
    });
    query.Query.Execute();
    ```

### Display Query Results

1. Retrieve the query results using the [GetQueryData](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.GetQueryData.html) method of the **Workspace** class. Finally, print the query results on the Console window using the [Write](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine.Api/C1.DataEngine.DataList.Write.html) method of the [DataList](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine.Api/C1.DataEngine.DataList.html) class.

    ```csharp
    //Output query results in CSV format to the console
    IDataList sales = workspace.GetQueryData("SalesByCountry");
    Console.WriteLine("Sales by Country:");
    DataList.Write(sales, Console.Out);
    ```