Search This Blog

Loading...
Showing posts with label SubSonic. Show all posts
Showing posts with label SubSonic. Show all posts

Friday, July 11, 2008

Using "select in" with SubSonic

While looking for SubSonic related information on something totally unrelated, I came across a post about trying to use the T-SQL "in" keyword to build a SubSonic collection at http://www.vitaminzproductions.com/technology-blog/index.php/2008/06/25/subsonic-select-where-in-solution. If that sounds confusing, imagine that you would like to have SubSonic return data that you would usually get with the following T-SQL statement:

select *
from MyTable 
where id in ('val1', 'val2', 'val3')

The author of the blog post had a solution but it was not one I liked. It seemed like a hack and I hate hacks. So, I took a few minutes and here is the result. The key is using the new SubSonic.Select query available in SubSonic v2.1. The code offers 3 different ways to accomplish the task.
C# Code:
// Define your collection object
MyTableCollection MyTableQuery;

// Define an array list for the first example
ArrayList ids = new ArrayList();
// Add some Guid values to the array list
ids.Add(new Guid("80FB189C-C3EA-4774-B15E-018DA88D3FE2"));
ids.Add(new Guid("88DE9C1D-26A7-4545-AA1E-01BDAEFF0588"));
    
// Poplulate the collection using an array list
MyTableQuery = new SubSonic.Select()
 .From(MyTable.Schema)
 .Where(MyTable.Columns.Id)
 .In(ids)
 .ExecuteAsCollection();

// Poplulate the collection using an array of strings
MyTableQuery = new SubSonic.Select()
 .From(MyTable.Schema)
 .Where(MyTable.Columns.Id)
 .In(new string[] {
  "80FB189C-C3EA-4774-B15E-018DA88D3FE2",
  "88DE9C1D-26A7-4545-AA1E-01BDAEFF0588"})
 .ExecuteAsCollection();
    
// Poplulate the collection using an inline select statement
MyTableQuery = new SubSonic.Select()
 .From(MyTable.Schema)
 .Where(MyTable.Columns.Id)
 .In(new SubSonic.Select(MyTable.Columns.Id)
 .Top("3")
 .From(MyTable.Schema))
 .ExecuteAsCollection();
VB.NET Code:
' Define your collection object
Dim MyTableQuery As MyTableCollection

' Define an array list for the first example
Dim ids As New ArrayList

' Define an array list for the first example
ids.Add(New Guid("80FB189C-C3EA-4774-B15E-018DA88D3FE2"))
ids.Add(New Guid("88DE9C1D-26A7-4545-AA1E-01BDAEFF0588"))

' Poplulate the collection using an array list
MyTableQuery = New SubSonic.Select() _
    .From(MyTable.Schema) _
    .Where(MyTable.Columns.Id) _
    .In(ids).ExecuteAsCollection(Of MyTableCollection)()

' Poplulate the collection using an array of strings
MyTableQuery = New SubSonic.Select() _
    .From(MyTable.Schema) _
    .Where(MyTable.Columns.Id) _
    .In(New String() {"80FB189C-C3EA-4774-B15E-018DA88D3FE2", "88DE9C1D-26A7-4545-AA1E-01BDAEFF0588"}) _
    .ExecuteAsCollection(Of MyTableCollection)()

' Poplulate the collection using an inline select statement
MyTableQuery = New SubSonic.Select() _
    .From(MyTable.Schema) _
    .Where(MyTable.Columns.Id) _
    .In(New SubSonic.Select(MyTable.Columns.Id) _
    .Top("3") _
    .From(MyTable.Schema)) _
    .ExecuteAsCollection(Of MyTableCollection)()

Thursday, April 10, 2008

Code Camp 9 Presentations

This past weekend, I attended Code Camp 9 in Waltham, MA and gave two presentation:

  • No Pain Database Access with Subsonic
  • Windows and Development Automation with NAnt

I am finally getting around to posting the presentation materials and supporting files here. So here goes.

No Pain Database Access with Subsonic

While I was disappointed with the turnout for this presentation and with my preparation, I learned a couple of things:

  1. I know very little about SubSonic. It's far from only an ORM framework, it's much more, and I don't know didly about it.
  2. I got to stop procrastinating

The presentation is available in two forms:

  1. Online at Google Docs:
    http://docs.google.com/Present?docid=dcz9szc5_25cz3xbtcx&skipauth=true
  2. PDF format:
    http://tech-cats.net/blog/downloads/dotnet/codeCamp9/NoPainDatabaseAccessWithSubSonic.pdf

Support files are also available in two forms:

  1. Online at Google Docs:
    http://docs.google.com/View?docid=dcz9szc5_28f8wb97fc
  2. HTML version:
    http://tech-cats.net/blog/downloads/dotnet/codeCamp9/No_Pain_Database_Access.html

Downloads

 

Windows and Development Automation with NAnt

I love NAnt. This presentation turned out great. I was prepared, I had lots of examples and people were interested - cool!

Again, the presentation is available in two forms:

  1. Online at Google Docs:
    http://docs.google.com/Present?docid=dcz9szc5_24fzjs9zgc&skipauth=true
  2. PDF format:
    http://tech-cats.net/blog/downloads/dotnet/codeCamp9/WindowsAndDevelopmentAutomationWithNAnt.pdf

Support Files:

  1. Online at Google Docs:
    http://docs.google.com/Doc?id=dcz9szc5_26gnfrmkfv
  2. HTML version:
    http://tech-cats.net/blog/downloads/dotnet/codeCamp9/Windows_and_Development.html

Downloads