February 08, 2007

HowTo: Strongly Typed View with SubSonic

I had a little trouble yesterday trying to get a Strongly Typed view working correctly in SubSonic. I spent a good 2 hours beating my brain trying to figure it out (I don't have internet at home yet - no Googling). Well after an hour break I came back and it hit me. It's very easy to implement, so lets start.

First off SubSonic will create your view as a collection. If your view is named v_RecentShares then you'll get a VRecentSharesCollection object.

You can then use that to query your view and iterate with a Strongly Typed reference:

Dim V as VRecentSharesCollection() = new VRecentSharesCollection().Load()
Dim Row as VRecentShares()
For Each Row in V
Dim ShareName as String = Row.ShareName

kick it on DotNetKicks.com