开发者

ASP.net: Efficient ways to convert DataSets to GenericCollection (Of ObjectType)

开发者 https://www.devze.com 2022-12-20 23:11 出处:网络
I currently have a function that gets some data from the database and puts it into a dataset. The return type on my function is GenericCollection (Of CustomerDetails)

I currently have a function that gets some data from the database and puts it into a dataset. The return type on my function is GenericCollection (Of CustomerDetails)

If I do this:

Dim dataset As DataSet = Read(strSQL.ToString) 'Gets Data from DB

What's the most efficient way to map the dataset results to an collection of objects. More importantly, since I'm using GenericCollection, is there a way to do this in which I can call a function from the ObjectType class (CustomerDe开发者_如何学运维tails) that would have a means to converting that specific object.

Or is there a way in which I can use a function that would handle all types?

Is there a way to do something like:

Return returnedResults.TransformDataSet(dataset) 

In which returnedResults is an object collection Of CustomerDetails, or would it simply be easier to have TransformDataSet return an object collection Of CustomerDetails by itself?

Thanks for any help.


Do you plan to generate the dataset, create your collection, then throw away the dataset? If so, I would suggest dispensing with the dataset completely, and use a data reader (SqlDataReader if you are using sql server). You can iterate through the reader and create your collection as you go.

The dataset is a heavy, xml-based gadget that is great if you need to keep it around and use it for other stuff, but if you are just going to use it as a temporary intermediate data store between the db and you collection, then I would lose it.

0

精彩评论

暂无评论...
验证码 换一张
取 消