views:

2051

answers:

6

When using SubSonic, do you return the data as a dataset or do you put that in a strongly typed custom collection or a generic object?

I ran through the subsonic project and for the four stored procs I have in my DB, it gave me a Sps.cs with 4 methods which return a StoredProcedure object.

If you used a MVC, do you usually use the StoredProcedure object or wrap that around your business logic and return a dataset, list, collection or something else?

Are datasets still the norm or is that replaced by something else?

+5  A: 

If the results of the stored procedure has the same schema as one of your tables, you can build a collection using this code (SubSonic 2.1):

ProductCollection coll = new ProductCollection();
coll.LoadAndCloseReader(SPs.GetProducts(1).GetReader());
John Sheehan
+1  A: 

If my stored procedure returns all the fields from one of the tables for which I have a SubSonic object then I do a LoadAndCloseReader on the result of the stored procedure. If my stored procedure returns data that does not match a SubSonic object then I just work with it as a dataset.

JPrescottSanders
A: 

my stored procedures return data from a few different tables and the data is massaged a bit too.

A: 

Perhaps return a datareader and then iterate it to populate some custom objects. Alternatively the quick and dirty way (since you're not using domain driven design) create a view in the DB with the same structure as the stored proc, then load the result into your ViewObjectCollection similar to John's code.

Steven Quick
A: 

You can do data readers, but that's so 1999. Returning objects is a breeze with SubSonic, and easier to use than a data reader. You can retrieve objects like so:

Dim Charts As Generic.List(Of MusicDB.Billboard) = _
    New SubSonic.Select(MusicDB.DB.Repository.Provider, New String() _
    {"Prefix", "Artist", "Track", "ArtistNarrowToken", "TrackNarrowToken", "ArtistId", "TrackId", "TrackYear"}). _
    From(MetadataTagger.MusicDB.Tables.Billboard). _
    Where(MusicDB.Billboard.Columns.ArtistNarrowToken).IsLessThan(10). _
    Or(MusicDB.Billboard.Columns.TrackId).IsNull(). _
    OrderAsc(New String() {"TrackYear"}).ExecuteTypedList(Of MetadataTagger.MusicDB.Billboard)()
Rick Ratayczak
Yikes. How is that easier than a data reader?
Robert S.
it's a lot like link2sql. it "may" not be easier, but it's easier to read, and it's strongly typed.
Rick Ratayczak
A: 

ExecuteTypedList<> is your best friend in this case:

IList list=SPs.GetProducts().ExecuteTypedList< Product >();

Rob Conery