Skip to content
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

Add Support for Dynamic Collection Names in LINQ Queries #384

Open
anilsnl opened this issue Nov 23, 2024 · 0 comments
Open

Add Support for Dynamic Collection Names in LINQ Queries #384

anilsnl opened this issue Nov 23, 2024 · 0 comments

Comments

@anilsnl
Copy link

anilsnl commented Nov 23, 2024

Hello,

Currently, when using the Couchbase.Linq library, it is not possible to dynamically specify a collection name while executing LINQ queries. This is a feature commonly available in MongoDB’s .NET driver through methods like IMongoDatabase.GetCollection(), which allows developers to dynamically pass the collection name and immediately execute LINQ queries using AsQueryable().

For example, in MongoDB, one can write:

var collection = database.GetCollection<User>(User.GetCollectionName(appCode)).AsQueryable();
var users = collection.Where(u => u.Role == "admin").ToList();

This flexibility is extremely useful in multi-tenant applications where collection names are determined at runtime based on the tenant or application context.

In Couchbase, achieving similar functionality requires using N1QL queries and dynamic string interpolation, which lacks the type safety and readability of LINQ queries.

Feature Request:
Add support for dynamically specifying collection names within LINQ queries in the Couchbase.Linq library. For instance, it would be beneficial to have an API like:

var context = new BucketContext(bucket);
var collection = context.GetCollection<User>("dynamicCollectionName").AsQueryable();
var users = collection.Where(u => u.Role == "admin").ToList();

This feature would greatly enhance developer productivity, improve type safety, and align Couchbase LINQ capabilities with other database drivers that support dynamic collection names.

Thank you for considering this request!

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

No branches or pull requests

1 participant