EF6 alpha Async Await on an Entity Stored Procedure / Function Import?

前端 未结 2 1596
耶瑟儿~
耶瑟儿~ 2021-01-13 07:13

I\'d like to apply the new async await functionality to Stored Procedures / Function Imports imported in my Entity model, but have as yet been unable to with the EF6 alpha.<

2条回答
  •  失恋的感觉
    2021-01-13 07:31

    This is an old thread, but I felt I should share. You should use APM then wrap the synchronous calls in a Task.

    Example:

    //declare the delegate
    private delegate MyResult MySPDelegate();
    
    // declare the synchronous method
    private MyResult MySP()
    {
        // do work...
    }
    

    Then wrap the synchronous method in a Task:

    // wraps the method in a task and returns the task.
    public Task MySPAsync()
    {
        MySPDelegate caller = new MySPDelegate(MySP);
        return Task.Factory.FromAsync(caller.BeginInvoke, caller.EndInvoke, null);
    }
    

    Call the async method when you want to execute:

    var MyResult = await MySPAsync();
    

    You can use up to three (3) parameters in the methods. Best practice is if you use more than three parameters; you should pass in a class.

提交回复
热议问题