Skip to content

MongoDB integration#25

Open
koenbeuk wants to merge 4 commits intomainfrom
feat/mongo-integration
Open

MongoDB integration#25
koenbeuk wants to merge 4 commits intomainfrom
feat/mongo-integration

Conversation

@koenbeuk
Copy link
Copy Markdown
Collaborator

@koenbeuk koenbeuk commented Apr 7, 2026

Integrate MongoDB support into ExpressiveSharp, including the addition of MongoDB.Driver and Testcontainers.MongoDb packages. Implement a new queryable interface and related functionality to enable LINQ queries with expressive syntax for MongoDB collections. Include integration tests to verify the new features.

Copilot AI review requested due to automatic review settings April 7, 2026 16:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class MongoDB support to ExpressiveSharp by introducing a MongoDB-specific query provider/wrapper that expands [Expressive] members before MongoDB LINQ translation, plus a new integration test suite running against a containerized MongoDB instance.

Changes:

  • Introduces ExpressiveSharp.MongoDB with an IMongoQueryProvider decorator and IExpressiveMongoQueryable<T> wrapper.
  • Adds MongoDB-specific polyfill async stubs (generator-intercepted) and default transformer options tailored for MongoDB LINQ translation.
  • Adds MongoDB integration tests + CI job using Testcontainers.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/TransformerPipelineTests.cs Validates transformer pipeline output is translatable by Mongo LINQ; includes custom options test.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/PolyfillInterceptorTests.cs Verifies generator interception for delegate-based LINQ in Mongo queries.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/ExpressiveMongoQueryProviderTests.cs Exercises provider-level [Expressive] expansion in select/where/orderby scenarios.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/ExpressiveMongoQueryableTests.cs Ensures wrapper/provider types are preserved and Mongo-specific APIs still work.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/ExpressiveMongoCollectionTests.cs Validates higher-level collection wrapper delegates CRUD and supports LINQ.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/EmbeddedDocumentTests.cs Validates [Expressive] expansion works with embedded documents/null-conditional chains.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Tests/AsyncMethodTests.cs Validates Mongo async operations work through the delegate-lambda chain.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Infrastructure/MongoTestBase.cs Creates per-test DB, seeds embedded documents, and cleans up databases.
tests/ExpressiveSharp.MongoDB.IntegrationTests/Infrastructure/MongoContainerFixture.cs Manages a MongoDB Testcontainers lifecycle at assembly scope.
tests/ExpressiveSharp.MongoDB.IntegrationTests/ExpressiveSharp.MongoDB.IntegrationTests.csproj New MSTest project referencing MongoDB + Testcontainers + generator analyzer.
src/ExpressiveSharp.MongoDB/MongoExpressiveOptions.cs Provides MongoDB-oriented default transformer pipeline.
src/ExpressiveSharp.MongoDB/Infrastructure/ExpressiveMongoQueryProvider.cs Decorates IMongoQueryProvider to expand expressions before execution.
src/ExpressiveSharp.MongoDB/Infrastructure/ExpressiveMongoQueryable.cs Wraps IQueryable<T> so chained operations keep the expressive provider.
src/ExpressiveSharp.MongoDB/IExpressiveMongoQueryable.cs Marker interface for MongoDB queryables that support rewrite/interception.
src/ExpressiveSharp.MongoDB/Extensions/MongoExpressiveExtensions.cs Entry points to wrap Mongo queryables/collections with expressive expansion.
src/ExpressiveSharp.MongoDB/Extensions/ExpressiveQueryableMongoExtensions.cs Generator-intercepted async stubs targeting MongoQueryable.
src/ExpressiveSharp.MongoDB/ExpressiveMongoCollection.cs Convenience wrapper around IMongoCollection<TDocument> exposing expressive LINQ.
src/ExpressiveSharp.MongoDB/ExpressiveSharp.MongoDB.csproj New MongoDB integration project (adds MongoDB.Driver).
ExpressiveSharp.slnx Adds new MongoDB projects to the solution.
Directory.Packages.props Adds package versions for MongoDB.Driver and Testcontainers.MongoDb.
.github/workflows/ci.yml Adds a dedicated MongoDB container test job.
.devcontainer/devcontainer.json Adjusts Docker-in-Docker feature configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +31
public IEnumerator<T> GetEnumerator() => _source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_source).GetEnumerator();
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

GetEnumerator() delegates directly to _source, which executes the query using the underlying Mongo provider and bypasses ExpressiveMongoQueryProvider.Execute/ExecuteAsync (so [Expressive] expansion may not happen for synchronous enumeration like foreach / ToList()). Implement enumeration via the wrapper Provider (e.g., execute Expression through _provider) so execution always flows through the expanding provider.

Suggested change
public IEnumerator<T> GetEnumerator() => _source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_source).GetEnumerator();
public IEnumerator<T> GetEnumerator()
{
var result = _provider.Execute<IEnumerable<T>>(Expression);
return result.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Copilot uses AI. Check for mistakes.
{
// Use custom options with no transformers — raw expansion only
var customOptions = new ExpressiveOptions();
var customQuery = MongoDB.Extensions.MongoExpressiveExtensions.AsExpressive(
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

MongoDB.Extensions.MongoExpressiveExtensions doesn’t exist in this repo (the extension is ExpressiveSharp.MongoDB.Extensions.MongoExpressiveExtensions). This will not compile; call the correct extension method/namespace (or just use Orders.AsExpressive(customOptions)).

Suggested change
var customQuery = MongoDB.Extensions.MongoExpressiveExtensions.AsExpressive(
var customQuery = ExpressiveSharp.MongoDB.Extensions.MongoExpressiveExtensions.AsExpressive(

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +28
var results = await Orders.AsQueryable()
.AsExpressive()
.Select(o => o.Total)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

These .AsExpressive() calls will currently bind to ExpressiveSharp.Extensions.ExpressiveQueryableExtensions.AsExpressive (because ExpressiveSharp.MongoDB.Extensions isn’t imported), which won’t install ExpressiveMongoQueryProvider and will leave [Expressive] members unexpanded for Mongo translation. Import/use the MongoDB integration AsExpressive extension explicitly to ensure the provider decoration happens.

Copilot uses AI. Check for mistakes.
koenbeuk and others added 3 commits April 7, 2026 18:14
…nterceptorTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines +45 to +48
catch
{
return false;
}
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.

2 participants