C# .NET Core 中的谓词
Predicate in C# .NET Core
我仍然是 .NET 和 .NET Core 的初学者。我不确定 predicate 的语法在 .NET CORE 中是如何工作的。
[HttpGet]
public async Task<IEnumerable<TodoItem>> GetAllAsync()
{
var items = await DocumentDBRepository<TodoItem>.GetItemsAsync(t => t.IsComplete);
return items;
}
上面代码中的 GetItemsAsync() 在 .NET Core 框架中有红色下划线,但在 .NET 框架中没有。
GetItemAsync() 的签名是:
public static async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate)
错误信息是
> "The call is ambiguous between the following methods or properties:
> "DocumentDBRepository<T>.GetItemsAsync(Expression<Func<T, bool>>)" and
> "DocumentDBRepository<T>.GetItemsAsync(Func<TodoItem, body>)"
谁能解释一下为什么?
class 中还有另一个 GetItemsAsync(Func)。这两个函数具有不同的参数。在我评论了这个函数 GetItemsAsync(Func) 之后它起作用了。
感谢@NetMage
我仍然是 .NET 和 .NET Core 的初学者。我不确定 predicate 的语法在 .NET CORE 中是如何工作的。
[HttpGet]
public async Task<IEnumerable<TodoItem>> GetAllAsync()
{
var items = await DocumentDBRepository<TodoItem>.GetItemsAsync(t => t.IsComplete);
return items;
}
上面代码中的 GetItemsAsync() 在 .NET Core 框架中有红色下划线,但在 .NET 框架中没有。
GetItemAsync() 的签名是:
public static async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate)
错误信息是
> "The call is ambiguous between the following methods or properties:
> "DocumentDBRepository<T>.GetItemsAsync(Expression<Func<T, bool>>)" and
> "DocumentDBRepository<T>.GetItemsAsync(Func<TodoItem, body>)"
谁能解释一下为什么?
class 中还有另一个 GetItemsAsync(Func)。这两个函数具有不同的参数。在我评论了这个函数 GetItemsAsync(Func) 之后它起作用了。
感谢@NetMage