ADO.NET数据表与数据读取器数据表、读取器、数据、ADO

2023-09-03 06:40:45 作者:半朵雲半顆訫

DataReader的是不是一个DataTable更有效,如果你只需要显示数据,但不能对其进行操作。然而,为了获得数据访问层一个DataReader我要离开Connection对象打开?我想这也是一个非常大的效率问题。所以有,以便采取DataReader的充分利用?另一种方法中,以这

The DataReader is more efficient than a DataTable if you only need to show data but not manipulate it. However, to get a DataReader from the data access layer should I leave the connection object open? I think this is also a very big efficiency problem. So is there another approach to this in order to take full advantage of the DataReader?

推荐答案

是的,数据读取器绝对是最有效的 - 但你的不可以要保持连接打开长时间时间!

Yes, the data reader is definitely the most efficient - but you do not want to keep a connection open for a long period of time!

使用的DataReader 来读取数据到一个实体对象;打开连接,读取数据,关闭连接 做任何你需要做的与您的业务对象 存储更改回来,例如通过使用即席SQL查询,存储过程,或任何你想要的东西;再次:打开连接,写回修改,关闭连接 use the DataReader to read your data into an entity object; open the connection, read the data, close the connection do whatever you need to do with your business object store the changes back, e.g. by using an ad-hoc SQL query, a stored procedure, or whatever else you want; again: open the connection, write back the changes, close the connection

这可能是最有效的,你可以得到 - 这是一些工作,有些无聊code,和所有的,但它一样快,因为它可以

This is probably the most efficient you can get - it's a bit of work, some boring code, and all, but it's about as fast as it can be.

如果你更感兴趣的开发人员的生产力比原始速度,为什么不使用某种类型的ORM做这一切的无聊,烦人的映射来回?保存的您的大量的编码和凌乱的东西来维持!

If you're more interested in developer productivity than raw speed, why not use some kind of an ORM to do all this boring, annoying mapping back and forth? Saves you a lot of coding and messy stuff to maintain!

 
精彩推荐
图片推荐