Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

.NET/C# quick start

Use Fauna’s .NET/C# driver to query e-commerce demo data in a .NET app. The driver requires .NET 8.0 or later.

 

  1. Create a database with demo data

    Log in to the Fauna Dashboard, and create a database with the following configuration:

    • Region Group: Choose your preferred region group, which determines where your data resides.

    • Use demo data: Enabled.

    • Enable backups: Disabled.

    Leave the other options as is.

    Create demo database

  2. Create an authentication secret

    Fauna supports several types of authentication secrets. For this quick start, create a key, which is a type of secret, with the built-in server-readonly` role:

    1. In the Dashboard’s Explorer page, select your demo database.

    2. In the database’s Keys tab, click Create Key.

    3. Choose a Role of server (read-only).

    4. Click Save.

    5. Copy the Key Secret.

    Create a key

  3. Set the FAUNA_SECRET environment variable

    Set the FAUNA_SECRET environment variable to your key’s secret. Fauna’s client drivers can access the secret from this variable.

    export FAUNA_SECRET=<KEY_SECRET>
  4. Install the .NET/C# driver

    Create a new directory for your app and install the .NET/C# driver:

    mkdir app
    cd app
    dotnet new console
    dotnet add package Fauna
  5. Create a query script

    In the app directory, edit the Program.cs file and replace the code with the following:

    using Fauna;
    using Fauna.Exceptions;
    using static Fauna.Query;
    
    try
    {
        // Initialize the client to connect to Fauna
        // using the `FAUNA_SECRET` environment variable.
        var client = new Client();
    
        // Compose a query using an FQL template string.
        // The query calls the `Product` collection's
        // `sortedByPriceLowToHigh()` index. It projects the `name`,
        // `description`, and `price` fields covered by the index.
        var query = FQL($@"
          Product.sortedByPriceLowToHigh() {{
            name,
            description,
            price
          }}
        ");
    
        // Run the query.
        var response = client.PaginateAsync<Dictionary<string, object?>>(query);
    
        await foreach (var page in response)
        {
            foreach (var product in page.Data)
            {
                Console.WriteLine(product["name"]);
                Console.WriteLine(product["description"]);
                Console.WriteLine(product["price"]);
                Console.WriteLine("--------");
            }
        }
    }
    catch (FaunaException e)
    {
        Console.WriteLine(e);
    }
  6. Run the script

    Run the script from the app directory. The script prints a list of e-commerce products from the demo data in the terminal.

    dotnet run

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!