[CSHARP-1340] Provide a type-safe way to create multikey indexes Created: 29/Jun/15  Updated: 29/Jun/15  Resolved: 29/Jun/15

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Robert Stam Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-1309 IndexKeysDefinitionBuilder should sup... Backlog

 Description   

As background, consider first the following classes:

public class Product
{
    public ObjectId Id;
    public Review Review;
}
 
public class Review
{
    public string Author;
    // etc...
}

Given these classes, one can easily create an index on the Author of a Review in a type-safe manner:

var builder = Builders<Product>.IndexKeys;
var keys = builder.Ascending(x => x.Review.Author);

However, suppose that instead of one Review, the Product class defined an enumerable of Reviews?

public class Product
{
    public ObjectId Id;
    public Review[] Reviews;
}

If you attempt to create an index on the Authors of the Reviews you get a compile time error:

var builder = Builders<Product>.IndexKeys;
var keys = builder.Ascending(x => x.Reviews.Author); // compile time error!

We need some way to support creating multikey indexes in a type-safe way.


Generated at Wed Feb 07 21:39:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.