I try to filter on of my mongo collections like that:
public IMongoCollection<T> GetCollection<T>()
where T : class
{
return _database.GetCollection<T>(typeof(T).Name);
}
public IMongoQueryable<TModel> Get<TModel>() where TModel : class
{
return GetCollection<TModel>().AsQueryable();
}
public async Task<TModel> FindOneAsync<TModel>(Expression<Func<TModel, bool>> predicate) where TModel : class
{
var foundEntity = await Get<TModel>().FirstOrDefaultAsync(predicate);
if (foundEntity == null)
{
throw new NotFoundException();
}
return foundEntity;
}
And then call it finally like that:
return await Db.FindOneAsync<Node>(node => node.Type == NodeType.Start);
But it seems like there is an error with the enum converter inside the mongo driver. I got the following error:
Application startup exception: System.AggregateException: One or more errors occurred. (Convert({document}.Type, Int32) is not supported.) ---> System.InvalidOperationException: Convert({document}.Type, Int32) is not supported.
Don't know what i am doing wrong. If i first cast the queryable to a list, then everything is working fine! But then the filter-operation is running on ram.