1

I'm using a SqlDataReader to populate an entity in a Winform app. The entity class has several foreign key attributes in the database that I want to setup as properties in the entity class. Each property will be of type 'Attribute' with an ID & Description property.

Some of the users of the system are far from the database, so data access performance is a serious consideration.

I could either execute the SqlCommand.ExecuteReader multiple times (once for each attribute) against a stored proc that returns a single resultset, or I could execute the SqlCommand.ExecuteReader once against a stored proc that returns multiple result sets and use the SqlDataReader.NextResult to move through them and setup the attributes.

If I loop through with .NextResult, I get into some issues with making sure the stored proc and the property assignment looping are aligned. If the order of SELECT statements in the proc change order, then the assignment order in the winform app would get messed up.

If the SqlDataReader goes back to the database for each read anyway, is there much time added executing the SqlCommand.ExecuteReader? Doing an ExecuteReader for each attribute would make things clearer on the assignment side.

Thanks!

4

1 回答 1

1

使用 .Nextresult,ADO.Net 不会为每个结果集返回数据库。所有这些逻辑都在 ADO.Net 数据提供程序中,无论它在哪里运行(在您的数据访问层中,可能在您的应用程序服务器上,或在您的 UI 层中,无论在哪里)

但是,如果您多次执行 datareader,则每次调用都会对数据库进行一次 rtound 访问。因此,如果执行此代码的层与数据库有一段距离(以往返时间计),则最好使用 .NextResult 技术。

您还应该考虑使用 DataSet(具有多个 DataTables)而不是数据读取器......您可能会发现这更高效。

于 2009-07-27T14:08:58.110 回答