[EF Provider] Support for HasIndex on nested objects

Given i have an object like this:

class Test
{
    public ObjectId Id { get; set; }
    public List<OtherObject> OtherObjects { get; set; }
}

class OtherObjects
{
    public string Name { get; set; }
    public string Value { get; set; }
}

I need to create an index in Name and Value, since i’ll be querying on those fields. Using driver i’m doing this:

var index = new CreateIndexModel<Test>(Builders<Test>.IndexKeys
            .Ascending("OtherObjects.Name")
            .Ascending("OtherObjects.Value")
        );

It would be great to have support for that using OwnsMany for model builder, something like this:

model.Entity<Test>().OwnsMany(x => x.OtherObjects, a =>
        {
            a.HasIndex(e => e.Name);
            a.HasIndex(e => e.Value);
        });

Do you think this is feasible to implement? For us it’s the last usage of Mongo.Driver for creating indexes, everything else we can do using the HasIndex function

Hi Jakub.

This is something we could implement but does require we create all the fluent API as obviously EF doesn’t have the methods for this itself.

I’ve created an issue in Jira to track this you can keep an eye on https://jira.mongodb.org/browse/EF-183

2 Likes

I mean, the api i showed with the OwnsMany exists, but i’m totally oblivious as to it being usable for MongoDB :slight_smile:

Thanks for looking at that, this would be super helpful