How SqlDataAdapter works internally?

我怕爱的太早我们不能终老 提交于 2019-12-05 16:25:43

It uses an internal facility of the SQL Server client classes which is called command sets. You can send multiple batches with a single command to SQL Server. This cuts down on per-call overhead. You have less server roundtrips and such.

A single row is updated per statement, and one statement per batch is sent, but multiple batches per roundtrip are send. The last point in this list is the magic sauce.

Unfortunately, this facility is not publicly exposed. Ayende took a hack on this and built a private-reflection bases API for it.

If you want more information I encourage you to look at the internal SqlCommandSet class.

That said, you can go faster than this by yourself: Transfer the update data using a TVP and issue a single UPDATE that updates many rows. That way you save all per-batch, per-roundtrip and per-statement overheads.

Such a query would look like this:

update T set T.x = @src.x from T join @src on T.ID = @src.ID
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!