Skip to content

Commit

Permalink
Refined GetByKey query approach after encountering issues where key c…
Browse files Browse the repository at this point in the history
…olumns are renamed.
  • Loading branch information
gmcelhanon committed Nov 6, 2024
1 parent 6571bd1 commit bca8328
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ private Aggregate GetAggregate()
return aggregate;
}

protected (QueryBuilder queryBuilder, string rootTableAlias) GetSingleItemQueryBuilder()
protected QueryBuilder GetSingleItemQueryBuilder()
{
// Get the fully qualified physical table name
Entity aggregateRootEntity = _aggregate.Value.AggregateRoot;
string rootTableAlias = aggregateRootEntity.IsDerived ? "b" : "r";

if (_queryBuilder != null)
{
return (_queryBuilder.Clone(), rootTableAlias);
return _queryBuilder.Clone();
}

var idQueryBuilder = new QueryBuilder(_dialect);
Expand Down Expand Up @@ -357,7 +357,7 @@ private Aggregate GetAggregate()

_queryBuilder = idQueryBuilder;

return (idQueryBuilder.Clone(), rootTableAlias);
return idQueryBuilder.Clone();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<IList<TEntity>> GetByIdsAsync(IList<Guid> ids, CancellationTok
if (SerializationEnabled)
{
// Get the item from serialized form
var (singleItemQueryBuilder, rootTableAlias) = GetSingleItemQueryBuilder();
var singleItemQueryBuilder = GetSingleItemQueryBuilder();

singleItemQueryBuilder.Where("Id", ids[0]);
var singleItemTemplate = singleItemQueryBuilder.BuildTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ string GetWhereClause(OrderedDictionary keyValues)
async Task<ItemData<TEntity>> GetItemData(OrderedDictionary compositeKeyValues, SessionScope scope)
{
// Get the item from serialized form
var (singleItemQueryBuilder, rootTableAlias) = GetSingleItemQueryBuilder();
var singleItemQueryBuilder = GetSingleItemQueryBuilder();

// Apply primary key values to the root (derived, if applicable) table, as that's how the composite key values are provided
foreach (DictionaryEntry keyValue in compositeKeyValues)
{
singleItemQueryBuilder.Where($"{rootTableAlias}.{(string) keyValue.Key}", keyValue.Value);
singleItemQueryBuilder.Where($"r.{(string) keyValue.Key}", keyValue.Value);
}

var singleItemTemplate = singleItemQueryBuilder.BuildTemplate();
Expand Down

0 comments on commit bca8328

Please sign in to comment.