Art of BI: Simple SubSonic Project Collection Retrieve

Using the subsonic project ORM for .NET clearly has tons of benefits for DAL and BLL purposes.

A great way to get a list of records from the db is to use the collection object which is created for tables and view objects from the db.

Here are two examples of how to use the .Load() method and overload to get data in a collection for which you can loop through using a foreach() statement.

Using the Query Object with Collection Object
[sourcecode language=’csharp’]
Query q = new Query(Views.Accounts);
q.WHERE(“accountID”, Comparison.Equals, _accountID.value.ToString());

AccountsCollection obj1 = new AccountsCollection();
obj1.Load(q.ExecuteReader());
[/sourcecode]

Using only the Collection Object
[sourcecode language=’csharp’]
AccountsCollection obj1 = new AccountsCollection().Where(“accountID”, Comparison.Equals, accountID.value.ToString()).Load();
[/sourcecode]
 

Now, to loop through the Collection
Once the collection has been instantiated and the Load() method called a foreach() loop can take place to get the records.
[sourcecode language=’csharp’]
if (obj1.Count > 0)
{
   foreach (Accounts x in obj1)
   {
      Console.Write(“My Account Name is {0}”, x.AccountName);
   }
}
else
   Console.Write(“There are no accounts in the collection”);
[/sourcecode]

Contact Us
Christian Screen
Christian is an innovator in analytics and data warehousing design, best practices, and delivery. With more than fifteenyears of decision support and data warehousing with key experiences at Office Depot HQ, Sierra-Cedar, and Capgemini, he oversees the Oracle Analytics Practice which includes the technical development and delivery of Oracle BI collaboration software, data warehouse solutions, Oracle BI/EPM projects, and packaged analytics solutions at Datavail.

Leave a Reply

Your email address will not be published.
Required fields are marked (*).