1

I have imported a stored procedure into my EF6 data model. Now I want to call that asynchronously, but it seems like EF doesn't create an Async version of the SP. Do I miss something here?

db.CallMyProcedure(param);
// vs
await db.CallMyProcedureAsync(param);
6
  • 4
    No. It's just that database-first (EDMX) is obsolete technology from a time that async-await didn't exist yet and the option was never added later. Commented Sep 12, 2019 at 12:14
  • 1
    I've never tried it, but await Task.Run(() => db.CallMyProcedure(param)); is not enough for your goal ? Commented Sep 12, 2019 at 12:15
  • @Miite: await Task.Run will call the same synchronous CallMyProcedure on a background thread which is not the same thing as calling an asynchronous method. You may use it to offload blocking work from the calling thread though. Commented Sep 12, 2019 at 12:34
  • @GertArnold It's the technology that is used in my company right now, so I don't really have a choice. Our current workflow is to create a Visual Studio database project first, lay down all the tables, views and stored procedures, publish it to our DB server and then create a model from it. Commented Sep 12, 2019 at 12:42
  • @mm8 The method, that uses this SPC, is just a SignalR wrapper. I don't think that putting a Task.Run around it would make it any better. Commented Sep 12, 2019 at 12:44

1 Answer 1

2

I kind of solved the problem by adding my own methods to the (luckily) partial model class:

using System.Data.SqlClient;
using System.Threading.Tasks;

namespace My.Softwares.Namespace.Model {
    public partial class DatabaseEntities {
        public virtual Task<int> CancelCurrentForkliftDeliveryAsync(int? iD_Carrier) {
            return Database.ExecuteSqlCommandAsync(
                "exec dbo.CancelCurrentForkliftDelivery @ID_Carrier",
                new SqlParameter("@ID_Carrier", iD_Carrier)
            );
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.