纠正这些方法并建议如何使用它们 [英] Correct these method and suggest how to use them
本文介绍了纠正这些方法并建议如何使用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public List<CustomerModel> GetAll()
{
List<CustomerModel> customers = new List<CustomerModel>();
db.Customers.ToList().ForEach(customer =>
{
customers.Add(new CustomerModel()
{
CustomerId = customer.CustomerId,
FirstName = customer.FirstName,
LastName = customer.LastName,
Address = customer.Address,
CreatedAt = customer.CreatedAt
});
});
return customers;
}
public async Task<List<CustomerModel>> GetAllAsync()
{
return await Task.Run((Func<List<CustomerModel>>)GetAll);
}
public Task<List<CustomerModel>> GetAllTask()
{
return new Task<List<CustomerModel>>(GetAll);
}
我无法使用await关键字调用GetAllTask方法。请帮助,并建议如何使用和制作纯粹的等待方法。
I am unable to call "GetAllTask" method with await keyword. please help and also suggest how to use and make pure awaitable methods.
推荐答案
这篇关于纠正这些方法并建议如何使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文