The MongoDB integration into EF Core 9.0 says it supports (and provides examples for) using the HasIndex() method of the Entity Builder to create indices. However, I can’t seem to get it to work.
This is my model setup code:
builder.Entity<GameDBObject>(bldr =>
{
bldr.HasIndex(dbobj => dbobj.Name).IsUnique(true);
bldr.HasIndex("Name").IsUnique(true);
// no index is created with either of the above two statements
bldr.HasKey(dbobj => dbobj.Id);
bldr.Property(dbobj => dbobj.Id)
.HasConversion(id => ObjectId.Parse(id), oid => oid.ToString())
.HasValueGenerator<StringObjectIdValueGenerator>();
});
I’ve tried both of the first two statements in the Entity Builder (giving the name of the property or a reference to it); neither results in an index being created.
How do I go about troubleshooting this?
In the debug logs, the only references I see to indexes are about the Id field in a contained GamePlayer object (which I tried changing to PlayerRef and it still complains about the Id field).