如何在 EF6 异步中启动实体存储过程而不等待返回? [英] How do I kick off an entity stored procedure in EF6 async and not wait for a return?

查看:25
本文介绍了如何在 EF6 异步中启动实体存储过程而不等待返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想直接调用 SQL Server,而不是等待返回.我有一个从存储过程导入的实体函数,我想在实体框架 6.0.0-rc1 中以这种方式异步调用它.这可能吗?语法是什么?

I'd like to just punt a call over to the SQL Server and not wait for a return. I have an imported Entity Function from a Stored Procedure that I'd like to call asynchronously this way in Entity Framework 6.0.0-rc1. Is this possible? What's the syntax?

Entity Function: RecalculateBudgetNumbers(int id)

推荐答案

启动一个新的 Task 来创建一个新的数据上下文并调用该函数.只是不要等待/等待那个任务.让它自己运行直到完成.

Start a new Task that creates a fresh data context and invokes that function. Just don't wait/await that task. Let it run by itself to completion.

确保记录错误.不要吞下异常,因为它们可能是您想了解的错误.

Make sure to log errors. Don't swallow exceptions because they might be bugs you want to know about.

在 ASP.NET 设置中,请注意工作进程可以随时回收,因此您的后台工作可能会突然消失(或被取消).

In an ASP.NET setting, be aware that the worker process can recycle at any time at all, so your background work can suddenly disappear (or be cancelled).

这篇关于如何在 EF6 异步中启动实体存储过程而不等待返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆