Data Data Library Returns a DataSet or Object

Is there a general consensus that when working with a library that calls stored procedures? Return datasets or use sqldatareader to populate custom objects?

Is the cost of serializing your data transfer facility less than a DataSet?

+4
source share
5 answers

Personally, I use SqlDataAdapter with DataTables. DataTables has fewer resources than DataSets. The objects of my object contain only business rules; they are not used to transfer data by levels.

+1
source

You might want to skip the data access library; instead, your business objects are automatically created for you, filled with data when you need them. NHibernate .

+1
source

I have to agree with justice, not necessarily about NHibernate (although this is a great option). I would definitely look at using some kind of ORM like NHibernate, Subsonic, Linq-to-sql, llblgen or any other of the ORMs around.

As Jeremy Miller states:

if you write the ADO.Net hand code, you steal from your employer or client.

and for this purpose I would have to recommend returning objects as opposed to datasets or datatables.

In addition, if you are returning datasets, unless you are typing a complete dataset, you will need to write a lot of “lifting” code in your library to get the values ​​from the datasets. With ORM and objects, all that heavy lifting is done for you.

Finally, with Linq in C #, you now get much better functionality for working with collections (aggregates, grouping, sorting, filtering, etc.) that could give datasets an edge.

+1
source

I also use dataReader, but keep in mind that if you do this, you have to be careful to close it (and the connection it uses) as quickly as possible after filling in the user objects ... One of them to be addressed attention is that when you call OpenReader (), make sure that you pass the optional CommandBehavior parameter set in CommandBehavior.CloseConenction, or even if you close the reader, the underlying connection will not be closed and released to the pool until it picks up GC, which can lead to then you will end the available connection if you call several reader objects in a loop.

0
source

At some point, it depends on the purpose of the library, or, I would say, the functionality of the library. Starting with OOP cheating, the “general consensus” is to first get / retrieve data in the DAL using datareaders as they are faster, then load your objects and close your readers, however this is not always the case. To keep things simple, some transmit the data set in such a way that gridviews can be limited and swap / sort can be enabled with minimal code. Remember that it is simple.

However, in the reporting application, I noticed a resemblance to data sets, especially if the data is opened by web services.

The cost of serialization will be based on the use of the application, as well as on experience. An inexperience developer can return from 3,000 to 50,000 rows of unnecessary data in a data set. Remember that a dataset is an animal, but with great functionality. Use wisely.

Most ORMs do serialization behind the scenes (I fix it here), so it’s fair to say that it won’t cost that much, but again it depends on the application.

0
source

All Articles