---
title: "Using the reporting foundation"
slug: "using-the-reporting-foundation"
abstract: "Describes how to use the reporting client"
---
# Using the reporting foundation

After following the installation in the previous step you’re ready to consume the reporting client.

<details>
<summary><h2>Resolving Reporting Client</h2></summary>

Reporting Client is registered in Sitecore IoC Container you can add IReportingClient as a dependency to your service if you’re using Sitecore DI.

Or resolve it via ServiceLocator Sitecore.DependencyInjection:

```text
Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService<IReportingClient>();

```

</details>

<details>
<summary><h2>Query Data</h2></summary>

To query data you can use the method GetFactAsync<TFact>(Action<IFactQueryOptionsBuilder>TFact>> builder) this method accepts a delegate in which it builds the query. Find the example below:

```csharp
await _reportingClient.GetFactAsync<ProductSales>(cfg =>
            {
                cfg.UseConnectionStringName("MyConnectionStringName")
                    .QueryFrom(DateTime.Now.AddYears(-1))
                    .To(DateTime.Now)
                    .ExpandDimension(o => o.Country)
                    .FilterWithKey("MY")
                    .ExpandDimension(o => o.Product);
            });

```

Notes:

- Reporting Client methods are asynchronous
- The query builder accepts a parameter which is a delegate that builds the query
- You’ve to pass the connection string name (e.g., reporting) in which you want to query data from (i.e., the database having your SQL Objects)
- QueryFrom…To will filter data based on the DateTime field in the fact object.
- ExpandDimension will include the dimension in the result
- FilterWithKey will filter the result based on the DimensionKey of the dimension

> [!note]
> The query must include at least one filter (either dimension or date time) and the connection string name otherwise a ValidationException will be thrown.

</details>

<details>
<summary><h2>Delete data</h2></summary>

Similar to Querying facts, Delete Facts also have the same filters. Find the below examples:

```csharp
await _reportingClient.DeleteFactsAsync<ProductSales>(cfg =>
            {
                cfg.UseConnectionStringName("MyConnectionStringName")
                    .DeleteFrom(DateTime.Now.AddYears(-1))
                    .To(DateTime.Now)
                    .DeleteThatHasDimension(o => o.Country)
                    .WithKey("MY");
            });

```

Notes

- Same filters are used (with different names) in the builder.
- The delete query builder must include at least one filter too and the connection string

</details>

<details>
<summary><h2>Add or update data</h2></summary>

To add or update data you use the method AddOrUpdate async and pass connection string name with a list of the data. Check the example below.

```text
await _reportingClient.AddOrUpdateAsync(_connectionStringName, data)

```

</details>