-
Notifications
You must be signed in to change notification settings - Fork 51
Description
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!