System.Data.IDbCommand和异步执行? [英] System.Data.IDbCommand and asynchronous execution?

查看:286
本文介绍了System.Data.IDbCommand和异步执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Data.SqlClient.SqlCommand 有方法

System.Data.SqlClient.SqlCommand has methods

BeginExecuteNonQuery
BeginExecuteReader
BeginExecuteXmlReader

EndExecuteNonQuery
EndExecuteReader
EndExecuteXmlReader

用于异步执行.

System.Data.IDbCommand 只有

System.Data.IDbCommand only has

ExecuteNonQuery
ExecuteReader
ExecuteXmlReader

仅用于同步操作.

是否有用于异步操作的接口?
另外,为什么没有BeginExecuteScalar?

Is there any interface for asynchronous operations ?
In addition, why is there no BeginExecuteScalar ?

推荐答案

IDbCommand不具有begin/end异步方法,因为在ADO.NET的原始.NET 1.1版本中尚不存在它们.异步方法已添加在.NET 2.0 中,将这些元素添加到IDbCommand中将是一项重大更改(将成员添加到接口对于该接口的实现者来说是一项重大更改).

IDbCommand does not have the begin/end async methods because they did not yet exist in the original .NET 1.1 release of ADO.NET, and when the async methods were added in .NET 2.0 it would have been a breaking change to add those to IDbCommand (adding members to an interface is a breaking change for implementors of that interface).

我不知道为什么BeginExecuteScalar不存在,但是可以将其实现为环绕BeginExecuteReader的扩展方法.总之,在.NET 4.5中,我们现在有了ExecuteScalarAsync,它更易于使用.

I don't know why BeginExecuteScalar doesn't exist, but it can be implemented as an extension method that wraps around BeginExecuteReader. Anyway in .NET 4.5 we now have ExecuteScalarAsync which is easier to use.

这篇关于System.Data.IDbCommand和异步执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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