Retrieving SQL Type Image Using LINQ

LINQ views the Image type in SQL Server as Binary. So, there are a few options that we have. We can either (a) modify our LINQ to SQL class and change the property to Byte() instead of Binary or we can (b) convert the Binary to an array. To do the latter, you can use a lambda expression to obtain the image you are looking for and grabbing just the image. Here’s an example:

MySqlContext.Photos.Single(Function(p) p.PhotoID = PhotoID).OriginalBytes.ToArray

The above assumes that we have a table called Photos that contains a column called PhotoID. We’ll filter the PhotoID (p.PhotoID) based on our variable PhotoID. Then, we’ll return the Byte Array of the OriginalBytes column to display our image.

Attention Twitter: Wise up!

I read through the Twitter blog from time to time just to see how things are going. Apparently, things aren’t going good. Pagination and IM updates have been temporarily disabled and something has caused my twitter utilities (twhirl and OutTwit) to cease function. I keep getting an error that shows "Rate limit exceeded. Clients may not make more than 30 requests per hour." Can you imagine if Twitter was an eCommerce shop and stopped a viewer after 30 page views? They’d slowly lose business. Does the Twitter team get that?

What about the limit of 140 characters? I know plenty of folks have complained about that. If you add a few individuals to your response, you’ll soon notice that you’re down to 100 characters. If you don’t understand short hand or Internet lingo, forget it. So this would be like going to the grocery store with a limit of $14. Hope you can get everything you need.

I’d really like to see Twitter merge with another social networking app like Facebook or FriendFeed. I’d even be ok with Microsoft, Apple, or Google purchasing them.

Before I forget, I might as well drop a line to my social profiles: Twitter, Facebook, and FriendFeed.

Force Your Web Site To Be IE7 Compatible

Microsoft recognizes that it will be difficult to have all sites use the latest HTML and CSS specs that are found in IE8. To accommodate the web sites that cannot be converted at this time, they’ve created a work around. There are two options: a) you can modify the config in IIS 7 or b) you can add a new meta tag to your page headers. More information about this can be found by visiting

SQL Management Studio Shows All Databases

This has "bugged" me for awhile. When you log into any version of SQL (2000, 2005, and even 2008) as a user with restricted access to just a single database (or even a few databases), you can still see a complete list of all the databases on that server. There have been times when I needed to share a database with a customer or have accessed a shared database at a host such as or GoDaddy and can see all of the customers on that one box. It’s more of a nuisance than a real threat but I really wish it was changed. It has been confirmed as a bug. Please vote for it at

Using "Like" in LINQ to SQL

I’ve recently discovered that LINQ and VB can be confusing. I was attempting to pull the top 10 rows of a table where the column started with ‘W’. You’d think after I typed that, I’d figure out the solution. That’s not the case. Instead, I struggled. Here’s what I originally came up with:

Dim q = From t In db.Employees Where t.LastName Like prefixText & "%" Select t.LastName Take count

Little did I realize that the Like operator in my query was the VB Like operator. So, I had to modify my lambda expression to this:

Dim q = From t In db.Employees Where t.LastName.StartsWith(prefixText) Select t.LastName Take count

You’ll notice that StartsWith makes more sense. <sigh> If only VB were…

Using LINQ to SQL and ConnectionStrings in a Class Library

I was looking to separate my LINQ to SQL data layer from the rest of my application. So, I decided to move the files to a class library. This way, when my application builds, all of my LINQ files are found in MyApp.DL or something similar. However, I wanted the class library to use the SQL connection that I have set in my web.config. Because the class library does not have a reference to System.Configuration, I had to add that first. I then created a partial class for my Context object. Inside, I created a new constructor with a boolean parameter called UseWebConfigConnectionString. My web.config would contain a generic connection string name called LinqSqlConnectionString.This allows me to make changes to the LINQ files, save them, and not affect this method. So, here’s what I ended up with:


    <add name="LinqSqlConnectionString" connectionString="{insert settings here};" providerName="System.Data.SqlClient"/>


Imports System.Configuration

Partial Public Class MyDataContext
    Public Sub New(ByVal UseWebConfigConnectionString As Boolean)
        MyBase.New(ConfigurationManager.ConnectionStrings("LinqSqlConnectionString").ConnectionString, mappingSource)
    End Sub
End Class


Dim db As New MyDataContext(True)

This seemed to be the easiest way to pull from my connection strings setting. Although, I’d highly recommend encrypting your connection string before deploying to production.

Obtain the Identity of a New Row Using LINQ

It’s actually pretty easy and user friendly to obtain the value of the identity column using LINQ. After you create your object and insert it on submit, you can call the identity column’s property on your object. For instance:

Dim db As New BlogDataContext()
Dim IdentityValue As Integer = MyPost.PostID

In this example, the IdentityValue variable would be assigned to the PostID of the post that was just submitted.

3G iPhone will Come In June

According to Gizmodo, the iPhone 3G launch date will be June 9th. It will be interesting to see what further market share the iPhone will capture with this latest phone. I know many individuals have held out from purchasing an iPhone because of the lack of 3G support. It will also be interesting to see what phones other providers will release to compete with the iPhone. For more details, visit