EventFlow
EventFlow copied to clipboard
Add an overload to `IMongoDbReadModelStore<TReadModel>.FindAsync()` for custom Queries
Linq To mongo doesn't support most methods for working with collections. For instances, something like:
public class SomeQuery : IQuery<IEnumerable<MyReadModel>>
{
public SomeQuery (IEnumerable<Reference> references)
{
References = references;
}
public IEnumerable<Reference> References { get; }
}
public async Task<IEnumerable<MyReadModel>> ExecuteQueryAsync(SomeQuery query, CancellationToken cancellationToken)
{
var cursor = await ReadModelStore.FindAsync(x => query.References.Any(z => z.ReferenceNumber == x.ReferenceNumber),
cancellationToken: cancellationToken);
var results = await cursor.ToListAsync();
return results;
}
Will not work, the Mongo Driver will report that a method is not supported, presumably the .Any().
Ideally, an overload for FindAsync() would be added to the IMongoDbReadModelStore<TReadModel> interface to allow for the passing of a Mongo Query constructed with Builders<MyReadModel>.Filter and so on.
I am happy to submit a PR, but wanted to make sure that there wasn't a reason to not expose that overload to begin with.