# DatAInsightsComposer Data Binding

The DatAInsightsComposer can work with a collection of different datasets where each dataset holds data of different type with different properties. This article describes the supported ways to supply data to the DatAInsightsComposer.

## Basics

The DatAInsightsComposer learns about its data through its `Datasets` parameter that can hold one or more [`DatasetDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.datainsightscomposer.datasetdescriptor) objects. Each dataset descriptor contains information about:

* Its unique `string` identifier and description.
* The data item property names and types as a `List` of [`DatasetFieldDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.datainsightscomposer.datasetfielddescriptor).
* The data items.

The DatAInsightsComposer requires each `DatasetDescriptor` to have an `Id` and `Fields`, but doesn't need the `Data` to be initially available. The app can [load the data on demand](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/data-binding#load-data-in-onpromptsubmit), depending on the user prompt or other business logic.

The app can provide data to the DatAInsightsComposer as:

* [Strongly-typed models](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/data-binding#strongly-typed-model)
* [Anonymous objects](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/data-binding#anonymous-objects)
* [`ExpandoObject`s](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/data-binding#expandoobject)

> tip The DatAInsightsComposer sends only dataset field metadata to the AI service. It does not send the actual data items.

## Strongly-Typed Model

> caption Using DatAInsightsComposer with strongly-typed data

```RAZOR.skip-repl
<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
                             @bind-Prompt="@DAICPrompt" />

@code {
    private string DAICPrompt { get; set; } = "Show all data in tabular format";

    private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };

    private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
    {
        new DatasetDescriptor()
        {
            Id = "sales-orders",
            Label = "Sales Orders",
            Description = "Sales orders by category, product, and country",
            Fields = new List<DatasetFieldDescriptor>()
            {
                new() { Name = "Category", Type = DatasetFieldType.String },
                new() { Name = "Product", Type = DatasetFieldType.String },
                new() { Name = "Country", Type = DatasetFieldType.String },
                new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
                new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
            }
        }
    };

    protected override void OnInitialized()
    {
        int dataItemCount = 100;
        int categoryCount = 3;
        int productCount = 10 + 1;
        int countryCount = 5;
        Random rnd = Random.Shared;

        List<DAICModel> data = new();

        for (int i = 1; i <= dataItemCount; i++)
        {
            int productNumber = Random.Shared.Next(1, productCount);
            int categoryNumber = productNumber % categoryCount + 1;
            int countryNumber = i % countryCount + 1;

            data.Add(new DAICModel()
            {
                Category = $"Category {categoryNumber}",
                Product = $"Product {productNumber}",
                Country = $"Country {countryNumber}",
                OrderDate = DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))),
                OrderValue = rnd.Next(12345, 98765)
            });
        }

        DAICDatasets.First(x => x.Id == "sales-orders").Data = data;

        base.OnInitialized();
    }

    public class DAICModel
    {
        public string Category { get; set; } = string.Empty;
        public string Product { get; set; } = string.Empty;
        public string Country { get; set; } = string.Empty;
        public DateOnly OrderDate { get; set; }
        public decimal OrderValue { get; set; }
    }
}
```

## Anonymous Objects

> caption Using DatAInsightsComposer with anonymous objects

```RAZOR.skip-repl
<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
                             @bind-Prompt="@DAICPrompt" />

@code {
    private string DAICPrompt { get; set; } = "Show all data in tabular format";

    private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };

    private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
    {
        new DatasetDescriptor()
        {
            Id = "sales-orders",
            Label = "Sales Orders",
            Description = "Sales orders by category, product, and country",
            Fields = new List<DatasetFieldDescriptor>()
            {
                new() { Name = "Category", Type = DatasetFieldType.String },
                new() { Name = "Product", Type = DatasetFieldType.String },
                new() { Name = "Country", Type = DatasetFieldType.String },
                new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
                new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
            }
        }
    };

    protected override void OnInitialized()
    {
        int dataItemCount = 100;
        int categoryCount = 3;
        int productCount = 10 + 1;
        int countryCount = 5;
        Random rnd = Random.Shared;

        List<DAICModel> data = new();

        for (int i = 1; i <= dataItemCount; i++)
        {
            int productNumber = Random.Shared.Next(1, productCount);
            int categoryNumber = productNumber % categoryCount + 1;
            int countryNumber = i % countryCount + 1;

            data.Add(new
            {
                Category = $"Category {categoryNumber}",
                Product = $"Product {productNumber}",
                Country = $"Country {countryNumber}",
                OrderDate = DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))),
                OrderValue = rnd.Next(12345, 98765)
            });
        }

        DAICDatasets.First(x => x.Id == "sales-orders").Data = data;

        base.OnInitialized();
    }
}
```

## ExpandoObject

> caption Using DatAInsightsComposer with ExpandoObject

```RAZOR.skip-repl
@using System.Dynamic

<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
                             @bind-Prompt="@DAICPrompt" />

@code {
    private string DAICPrompt { get; set; } = "Show all data in tabular format";

    private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };

    private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
    {
        new DatasetDescriptor()
        {
            Id = "sales-orders",
            Label = "Sales Orders",
            Description = "Sales orders by category, product, and country",
            Fields = new List<DatasetFieldDescriptor>()
            {
                new() { Name = "Category", Type = DatasetFieldType.String },
                new() { Name = "Product", Type = DatasetFieldType.String },
                new() { Name = "Country", Type = DatasetFieldType.String },
                new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
                new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
            }
        }
    };

    protected override void OnInitialized()
    {
        int dataItemCount = 100;
        int categoryCount = 3;
        int productCount = 10 + 1;
        int countryCount = 5;
        Random rnd = Random.Shared;

        List<object> data = new();

        for (int i = 1; i <= dataItemCount; i++)
        {
            int productNumber = Random.Shared.Next(1, productCount);
            int categoryNumber = productNumber % categoryCount + 1;
            int countryNumber = i % countryCount + 1;

            data.Add(CreateSalesItem(categoryNumber, productNumber, countryNumber));
        }

        DAICDatasets.First(x => x.Id == "sales-orders").Data = data;

        base.OnInitialized();
    }

    private ExpandoObject CreateSalesItem(int categoryNumber, int productNumber, int countryNumber)
    {
        Random rnd = Random.Shared;
        ExpandoObject item = new ExpandoObject();
        IDictionary<string, object?> values = (IDictionary<string, object?>)item;

        values.Add("Category", $"Category {categoryNumber}");
        values.Add("Product", $"Product {productNumber}");
        values.Add("Country", $"Country {countryNumber}");
        values.Add("OrderDate", DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))));
        values.Add("OrderValue", rnd.Next(1234, 9876));

        return item;
    }
}
```

## Next Steps

* [Configure the DatAInsightsComposer Visuzalization Components](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/components)
* [Implement Best Security Practices](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/security)
* [Manage the DatAInsightsComposer State](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/state)
* [Handle DatAInsightsComposer Events](https://www.telerik.com/blazor-ui/documentation/components/datainsightscomposer/events)

## See Also

* [DatAInsightsComposer API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.datainsightscomposer.telerikdatainsightscomposer)
