Skip to content

Comments

Create Entities in-memory from Autoentities#3129

Open
RubenCerna2079 wants to merge 22 commits intomainfrom
dev/rubencerna/create-inmemory-entities-from-autoentities
Open

Create Entities in-memory from Autoentities#3129
RubenCerna2079 wants to merge 22 commits intomainfrom
dev/rubencerna/create-inmemory-entities-from-autoentities

Conversation

@RubenCerna2079
Copy link
Contributor

@RubenCerna2079 RubenCerna2079 commented Feb 13, 2026

Why make this change?

  • Create entities in-memory from autoentities #3052
    We need to generate all the entities from the autoentities properties. In order to do this we need to use the query that was previously created and, add the newly generated entities into the runtime so the user can use them.

What is this change?

  • MsSqlMetadataProvider.cs: Finish creating the GenerateAutoentitiesIntoEntities function so that it uses the query to receive all of the tables and turn them into entities inside the runtimeConfig.
  • RuntimeConfig.cs: Create new function that adds the new entities to the runtimeConfig. And also change the runtimeConfig to allow for the entities property to be missing if the user decides to use the autoentities property.

How was this tested?

  • Integration Tests
  • Unit Tests

@RubenCerna2079 RubenCerna2079 added this to the Feb 2026 milestone Feb 13, 2026
@RubenCerna2079 RubenCerna2079 self-assigned this Feb 13, 2026
@RubenCerna2079 RubenCerna2079 linked an issue Feb 13, 2026 that may be closed by this pull request
@RubenCerna2079 RubenCerna2079 force-pushed the dev/rubencerna/create-inmemory-entities-from-autoentities branch from 1972a8f to 2f256e4 Compare February 13, 2026 00:52
@RubenCerna2079 RubenCerna2079 marked this pull request as ready for review February 13, 2026 01:13
Copilot AI review requested due to automatic review settings February 13, 2026 01:13
@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).


_entityNameToDataSourceName = new Dictionary<string, string>();
if (Entities is null)
if (Entities is null && this.Entities.Entities.Count == 0 &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition will throw NullException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not following why this would throw a NullException

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename Entities to entities since its a function argument

return _entityNameToDataSourceName.TryAdd(entityName, this.DefaultDataSourceName);
}

public bool TryAddEntityNameToDataSourceName(string entityName, string autoEntityDefinition)
Copy link
Collaborator

@Aniruddh25 Aniruddh25 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename the function to inform we are adding entity name from AutoentityDefinition

/// <returns>DataSourceName</returns>
public string GetDataSourceNameFromAutoentityName(string autoentityName)
{
CheckAutoentityNamePresent(autoentityName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 2 functions, why cant we use TryGet function? if false, you can throw exception.

{
await Task.CompletedTask;
RuntimeConfig runtimeConfig = _runtimeConfigProvider.GetConfig();
Dictionary<string, Entity> entities = new();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define entities where its needed. Since autoentities could still be null, defining here is pre-mature if we are just going to return.


if (runtimeConfig.IsRestEnabled)
{
_logger.LogInformation("[{entity}] REST path: {globalRestPath}/{entityRestPath}", entityName, runtimeConfig.RestPath, entityName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is only Rest information being logged?

foreach ((string autoentityName, Autoentity autoentity) in autoentities)
{
int addedEntities = 0;
JsonArray? resultArray = await QueryAutoentitiesAsync(autoentity);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when querying, are we asking the right datasource to query from? How is that information being passed to QueryAutoentitiesAsync?

if (GetDatabaseType() == DatabaseType.MSSQL)
{
await GenerateAutoentitiesIntoEntities();
await GenerateAutoentitiesIntoEntities(new Dictionary<string, Autoentity>(Autoentities));
Copy link
Collaborator

@Aniruddh25 Aniruddh25 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the need to create new dictionary of Autoentities here? cant you simply pass the Readonly dictionary?


Assert.IsTrue(loader.TryLoadConfig("dab-config.json", out RuntimeConfig runtimeConfig), "Should successfully load config");
Assert.IsTrue(runtimeConfig.SqlDataSourceUsed, "Should have Sql data source");
Assert.AreEqual(expectedEntities, runtimeConfig.Entities.Entities.Count, "Default datasource should be of root file database type.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message here seems to be not accurate.

"stocks_view_selected": {
"source": {
"object": "stocks_view_selected",
"type": "view",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test by naming the child data sources explicitly? I dont know if we provide the datasource name in the sample files or rely on the default one.


Assert.IsTrue(loader.TryLoadConfig("dab-config.json", out RuntimeConfig runtimeConfig), "Should successfully load config");
Assert.IsTrue(runtimeConfig.SqlDataSourceUsed, "Should have Sql data source");
Assert.AreEqual(expectedEntities, runtimeConfig.Entities.Entities.Count, "Default datasource should be of root file database type.");
Copy link
Collaborator

@Aniruddh25 Aniruddh25 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this runtimeConfig.Entities.Entities.Count include entities matching from all the data source files - including the ones that matched from autoentities ?

Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on addressing some questions..

@github-project-automation github-project-automation bot moved this from Todo to Review In Progress in Data API builder Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

Create entities in-memory from autoentities

3 participants