SubSonic and stored procedures

When using SubSonic, do you return data as a dataset or put it in a strongly typed user collection or shared object?

I went through a subsonic project and for the four stored processes that I have in my database, he gave me Sps.cs with 4 methods that return a StoredProcedure object.

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

Are data sets still the norm or are they being replaced by something else?

+2
source share
5 answers

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

ProductCollection coll = new ProductCollection(); coll.LoadAndCloseReader(SPs.GetProducts(1).GetReader()); 
+5
source

ExecuteTypedList<> is your best friend in this case:

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

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

+2
source

Perhaps return the datareader and then repeat it to populate some custom objects. Alternatively, the quick and dirty way (since you are not using a domain-driven project), create a view in the database with the same structure as the stored process, and then load the result into your ViewObjectCollection, similar to John code.

+1
source

You can do data readers, but that means 1999. Returnables are a breeze with SubSonic and easier to use than a data reader. You can get such objects:

 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)() 
0
source

All Articles