我使用this代码作为参考实现MongoDBRepository,但它给了我一个错误。
这是我的示例代码。
public static IMongoCollection<Book> Initialize()
{
MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress(host, 10255);
settings.UseSsl = true;
settings.SslSettings = new SslSettings();
settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;
MongoIdentity identity = new MongoInternalIdentity(dbName, userName);
MongoIdentityEvidence evidence = new PasswordEvidence(password);
settings.Credentials = new List<MongoCredential>()
{
new MongoCredential("SCRAM-SHA-1", identity, evidence)
};
MongoClient client = new MongoClient(settings);
var database = client.GetDatabase(dbName);
var bookCollection = database.GetCollection<Book>(collectionName);
return bookCollection;
}
public Task<IEnumerable<Models.Book>> GetBooksAsync(Expression<Func<Models.Book, bool>> predicate)
{
if (predicate == null) { throw new ArgumentNullException("Predicate is Null"); }
var client = Initialize();
return client.AsQueryable().Where(predicate);
}
它在最后一行代码中的谓词下显示红色下划线。错误消息显示:
Argument 2: cannot convert from 'System.Linq.Expressions.Expression<System.Func<BookProfile.Models.Book, bool>>' to 'System.Func<Book, bool>'
有人可以解释这个问题的原因是什么吗?