Yea, i’m sorry, the issue was on the other line. I think this is a bug, or maybe i’m doing something wrong:
var options = new CreateIndexOptions<ChartOfAccounts>
{
Unique = true,
// this filter will only index documents that have a string value for the Version1Id field. So it will ignore null values, which is what we want.
PartialFilterExpression = Builders<ChartOfAccounts>.Filter.Type(n => n.Version1Id, BsonType.String)
};
builder.HasIndex(n => n.Version1Id)
.HasCreateIndexOptions(options);
This filter works correctly on Driver, EF throws exception:
System.InvalidCastException: Unable to cast object of type 'MongoDB.Driver.CreateIndexOptions`1[GeneralLedger.Microservice.Data.Entities.ChartOfAccounts]' to type 'MongoDB.Driver.CreateIndexOptions`1[MongoDB.Bson.BsonDocument]'.
2025-01-22T16:06:38 at MongoDB.Driver.CreateIndexOptions`1.CoercedFrom(CreateIndexOptions options)
2025-01-22T16:06:38 at MongoDB.Driver.CreateIndexModel`1..ctor(IndexKeysDefinition`1 keys, CreateIndexOptions options)
2025-01-22T16:06:38 at MongoDB.EntityFrameworkCore.Storage.MongoClientWrapper.CreateIndexDocument(IIndex index, String indexName)
2025-01-22T16:06:38 at MongoDB.EntityFrameworkCore.Storage.MongoClientWrapper.CreateIndexesAsync(IEntityType entityType, CancellationToken cancellationToken)
2025-01-22T16:06:38 at MongoDB.EntityFrameworkCore.Storage.MongoClientWrapper.CreateDatabaseAsync(IDesignTimeModel model, CancellationToken cancellationToken)