Entity Framework 数据库优先方法 - 如何制作异步方法?

Entity Framework database-first approach - how to make async method?

我正在使用 Entity Framework 和数据库优先方法(如下所示)从存储过程生成方法。

public virtual ObjectResult<GetPersons_Result> GetPersons(Nullable<int> id)
{
    var idParameter = id.HasValue ?
            new ObjectParameter("id", id) :
            new ObjectParameter("id", typeof(int));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetPersons_Result>("GetPersons", idParameter);
}

为了以异步方式实现此 运行,我将此方法包装在 Task.Run() 中(如下所示)

public async Task<object> GetPersons(int id)
{
    IList<GetPersons_Result> persons;

    using (var context = new PersonEntities())
    {
         persons = await Task.Run(() => 
                        context.GetPersons(id).SingleOrDefault());
    }

    return persons;
} 

我们是否有任何其他选项来对此 EF 生成的方法进行异步调用?

    public static async Task PerformDatabaseOperations()
                {
                    using (var db = new BloggingContext())
                    {
                        // Create a new blog and save it
                        db.Blogs.Add(new Blog
                        {
                            Name = "Test Blog #" + (db.Blogs.Count() + 1)
                        });
                        Console.WriteLine("Calling SaveChanges.");
                        await db.SaveChangesAsync();
                        Console.WriteLine("SaveChanges completed.");

                        // Query for all blogs ordered by name
                        Console.WriteLine("Executing query.");
                        var blogs = await (from b in db.Blogs
                                    orderby b.Name
                                    select b).ToListAsync();

                        // Write all blogs out to Console
                        Console.WriteLine("Query completed with following results:");
                        foreach (var blog in blogs)
                        {
                            Console.WriteLine(" - " + blog.Name);
                        }
                    }
                }