Which method is effective for calling a stored procedure with async waiting in the Entity Framework

I am using Entity Framework 6, VS15, DOT NET 4.5.

After reading a couple of articles and posting questions here, I received several answers in order to make database operations asynchronous, now please offer me which method is effective in all the references below.

I added tables and a stored procedure in the Entity Framework and performed inserts with this. I really want to make an asynchronous call.

using (var DB = new JodoDataEntities()) { UserInfo UserInformation = await DB.UserInfoes.Where(x => x.Id == userInfo.UserId).FirstOrDefaultAsync(); if (UserInformation != null) { UserInformation.Accuracy = userInfo.Accuracy; UserInformation.IsOnline = userInfo.IsOnline; await DB.SaveChangesAsync(); return Ok(); } } 

This works fine, but I populate it, it calls the DB calls twice, first selects and then assigns values ​​in the properties, and then SaveChanges() . If everything happens in one call, that would be great.

Here UpdateLocation is my stored procedure:

 using (var DB = new JodoDataEntities()) { DB.UpdateLocation(userInfo.UserId, userInfo.Accuracy, userInfo.IsOnline); } 

It works fine on the code and with one request. but without asynchrony. And I need an asynchronous call.

Here UpdateLocation is my stored procedure:

 using (var DB = new JodoDataEntities()) { await DB.Database.SqlQuery<Task>("EXEC UpdateLocation {0}, {1}, {2}", userInfo.UserId, userInfo.Accuracy, userInfo.IsOnline).ToArrayAsync(); } 

The above code works fine and asynchronously. But the correct way to call a stored procedure?

Is there any other way to call stored procedures asynchronously with EF?

+5
source share

Source: https://habr.com/ru/post/1233911/


All Articles