Geeks With Blogs

Scott Kuhl Warning: I may have no idea what I am talking about!

For a more traditional object-oriented approach to multiple objects you can use the auto-generated collections.  Just like classes, SubSonic will also generate a collection for every table.  (The naming convention for collections is ClassCollection.)  These collections are implemented as Generic Lists that include some additional functionality.

Loading a Collection

The simplest way to load a collection is by calling the Load method with no parameters to retrieve every record.

ProductCollection products = new ProductCollection();
products.Load();

You can also pass the Load method an IDataReader, DataTable or SubSonic Query.

IDataReader reader = Product.FetchAll();
products.Load(reader);
reader.Close();

(Make sure you close the reader.  The Load method will not do this for you.)

Ordering a Collection

You can order a collection based on a single column by calling OrderByAsc or OrderByDesc before calling the Load method.

ProductCollection products = new ProductCollection();
products.OrderByAsc(Product.Columns.ProductName);
products.Load();

Filtering a Collection

You can filter a collection by calling BetweenAnd, Where or WhereDatesBetween before calling the Load method.

OrderCollection orders = new OrderCollection();
orders.BetweenAnd(Order.Columns.OrderDate, new DateTime(1980, 1, 12), DateTime.Now);
orders.Load();

The Where method works just like the SubSonic Query Where which is covered in the next section.

Find the entire series of posts here.

Posted on Wednesday, December 6, 2006 10:38 PM SubSonic | Back to top


Comments on this post: Getting Started with SubSonic - Part 13, Collections

# Namespace in DotNet
Requesting Gravatar...
# Namespace in DotNet
Hello All,

I have uploaded article regarding namespace in dotnet. Read It. It's really useful. How namespace works in .NET Framework

For more information "http://developmentwithdotnet.blospot.com"

Thanks
-Nimesh.
Left by Nimesh on Jul 28, 2009 10:14 PM

# re: Getting Started with SubSonic - Part 13, Collections
Requesting Gravatar...
Hi
How to use Where() with a collection object. The option is available with the collection object.But i don't know as i am a newbie. I want to use for ex.
OrderCollection orders = new OrderCollection();
orders.Where("Id",10);
But this doesn't works at all. Please tell me the right solution ASAP.

Thanks
Left by Ritesh Tandon on Dec 03, 2009 8:26 PM

# re: Getting Started with SubSonic - Part 13, Collections
Requesting Gravatar...
I'm pretty sure that should work. I don't know what exactly the problem is you are having. The problem may be the version of SubSonic you are using. You should ask your question on StackOverflow with the tag SubSonic. http://subsonicproject.com/docs/Questions
Left by Scott Kuhl on Dec 04, 2009 1:32 AM

# re: Getting Started with SubSonic - Part 13, Collections
Requesting Gravatar...
Hi,

Again i want to please look in to the problem i have a collection SubSonic.Generated.CarsearchCollection dtModel having 386 records in it.
When i use
dtModel.Where("EdId",stEd); //where stEd is any value
dtModel.Load();
The value of dtModel records doubles ie 772. I am still working with the problem i am not able to resolve what is wrong from last 1 month. Please Help me.

Thanks
Left by Ritesh Tandon on Dec 07, 2009 11:06 PM

# re: Getting Started with SubSonic - Part 13, Collections
Requesting Gravatar...
Again, you should ask your question on StackOverflow with the tag SubSonic. http://subsonicproject.com/docs/Questions

That is the official support route, not the comment system on this blog.
Left by Scott Kuhl on Dec 08, 2009 3:07 AM

# re: Getting Started with SubSonic - Part 13, Collections
Requesting Gravatar...
How to load two collection?
Thanks in Advance
Left by Harish on Dec 22, 2009 4:35 PM

Your comment:
 (will show your gravatar)


Copyright © Scott Kuhl | Powered by: GeeksWithBlogs.net