Skip to content

Context expressions - Add support for Scan and Query using LINQ #3872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: development
Choose a base branch
from

Conversation

irina-herciu
Copy link
Contributor

@irina-herciu irina-herciu commented Jun 11, 2025

This pull request introduces native support for LINQ expression trees in the IDynamoDBContext API for ScanAsync() and QueryAsync().

Description

Implement support to automatically translate LINQ expression trees to DynamoDB Expression

Example translation:
u => u.Age > 21 && u.Status == "Active"
becomes a ExpressionStatement like: #C0 > :C0 AND #C1 = :C1
with appropriate ExpressionAttributeNames and ExpressionAttributeValues.

  • Introduce ContextExpression that will be used to define filter LINQ expressions as follows:
var contextExpression = new ContextExpression();
contextExpression.SetFilter<Product>(p => p.CompanyInfo.Name == "Acme");

Add in LinqDdbExtensions methods to be used inside expression trees to generate DynamoDB Expression functions as follows:

  • Between
  • AttributeExists
  • AttributeNotExists
  • AttributeType

Extend IDynamoDBContext with a new overloads for Scan API:

IEnumerable<T> Scan<T>(ContextExpression filterExpression);
IEnumerable<T> Scan<T>(ContextExpression filterExpression, ScanConfig scanConfig);
  • Extend QueryConfig to allow setting ExpressionFilter as ContextExpression.
var resultExpressionFilter = Context.Query<Employee>("Diane", new QueryConfig
            {
                ExpressionFilter = contextExpression 
            }).ToList();

Motivation and Context

Testing

unit and integration tests added
benchmarking between filters methods and LINQ expression tree ones
image

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant