|
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.
|