Monday, June 09, 2008

LINQ and Stored Procedures Not Always Magic

I had an interesting experience while trying to import a stored procedure into a LINQ to SQL Classes Designer surface today.  Normally this is a pretty straightforward process.  First you open Server Explorer, then go to one of your connections, find the stored procedure, and then drag and drop it onto the designer surface.  Boom, it's suddenly available from your DataContext as a method. 

That's exactly what I did today, except when I created a var for the stored procedure result set, and then added a foreach to loop through the rows in the result set... nothing showed in my Intellisense.  Huh?  A little hover magic and I saw that my generated method was returning an int.

After some investigation, I found that the designer has a hard time handling stored procedures that use temporary tables in them, as it throws off the procedure meta data.  As it turns out, there are two possible solutions.  First, you can use a table variable instead:

DECLARE @tempTable TABLE ( ... )

Your second option is to continue to use a temporary table, but hand modify your dbml file using an XML editor.  Simply right click on the file in Solution Explorer and choose Open With and then choose your favorite XML editor.  Mine is Notepad2.  Search through the file for your stored procedure, which for a procedure named "storedProcedureName" might look like this:

<Function Name="dbo.storedProcedureName" Method="storedProcedureName">
  <Parameter Name="Parameter1" Parameter="Parameter1" Type="System.Int32" DbType="Int" />
  <Return Type="System.Int32" />
</Function>

Then remove the <Return ... /> element and replace it with an <ElementType> node which may look like this:

<Function Name="dbo.storedProcedureName" Method="storedProcedureName">
  <Parameter Name="Parameter1" Parameter="Parameter1" Type="System.Int32" DbType="Int" />
  <ElementType Name="storedProcedureNameResult">
    <Column Name="Result1" Type="System.Int32" DbType="int NOT NULL" CanBeNull="false" />
    <Column Name="Result2" Type="System.String" DbType="varchar(10) NOT NULL" CanBeNull="false" />
    <!-- ... -->
  </ElementType>
</Function>
This second method is the one that I used since my temporary table will hold thousands of rows, which is too inefficient for a table variable.
#    3:45 PM by Nick | No Comments |

How to Get a Geeky Guy

For all those ladies interested in catching a geeky guy... or keeping one once you've snagged him, here is a funny guide for you.  Via @larryclarkin.

#    8:31 AM by Nick | No Comments |
 Friday, June 06, 2008

Looking For Some Cool Free Software?

#    11:27 AM by Nick | No Comments |
 Wednesday, June 04, 2008

The Quoteable Coworker

The names, as always, have been withheld to protect the innocent...

Coworker 1:  I haven't exactly seen numbers showing .NET running circles around VB6 performance wise.
Coworker 2:  You haven't?  I'll go find some right now.
Coworker 1:  But not from Microsoft.
Coworker 2:  Why?  They created both, so they should be unbiased.

#    1:10 PM by Nick | No Comments |
 Monday, June 02, 2008

When Good XML Goes Bad

Coding Horror recently went after XML as being a rather poor option for many things.  I generally don't agree with that sentiment, but I do agree with the idea that there is good XML structure and bad.  Here is an example of bad XML structure that is required to use a control library from Janus.  This sample XML snippet is required to define the columns in their grid control:

<Columns Collection="true">
  <Column0 ID="">
    <Caption>Home Term</Caption>
    <EditType>NoEdit</EditType>
    <Position>0</Position>
    <Width>73</Width>
  </Column0>
  <Column1 ID="Column1">
    <Caption>Driver</Caption>
    <EditType>NoEdit</EditType>
    <Key>Column1</Key>
    <Position>1</Position>
  </Column1>
  <!-- ... -->
</Columns>
The controls so far look rather nice, and fairly functional and complete.  At issue here is the use of tag names like "Column0" and "Column1".  A well designed XML structure would just have "Column" tags, and then use some sort of extra identifier... which ironically... they already do!  Yet they require that the tag name matches the identifier.  Definitely not a good use of XML's inherent structure and definition abilities.
#    11:42 AM by Nick | No Comments |
 Thursday, May 29, 2008

Building a New Desktop Part I

This is the first in a multi-part series on building a new desktop computer.  To be honest, I've been horribly lax in my computer setup at home.  I've had desktops in the past, but have let them go unused in favor of various laptops that turned into my do-all machines.  As I looked at the things I've wanted to do going forward, and projects that I wish to undertake, I've realized that I need to offload some things onto a more dedicated server type machine, and under take new practices personally like my own source code control for personal projects.

I used to build new machines every few years, but haven't done it for a while, and haven't really even kept up to date on the latest hardware available.  But after reading a few articles on Coding Horror and Maximum PC, I've built up a nice parts list.  But before I share the list, I thought I'd share some of my goals for the machine.

Server:  This machine will not run a serve operating system as it's primary OS, but it will have many server like responsibilities.  I plan on using Vista Ultimate 64-Bit.  I'd like to run SQL Server, SVN, IIS, and potentially Mantis on this machine, as well as use it for basic file server and print server uses.

Testing:  I'd like to have multiple Virtual Machines running with different operating systems that I don't normally use in order to experiment and learn.  I'd like to have Windows Server 2008, Ubuntu, and possibly OS X installed as virtual machines.

Fun:  Yes, I'd like to have fun with this machine as well.  I'd like to be able to have decent media capabilities, and possibly be a stronger workhorse for more complicated photography operations and video editing.

Of course there is the old saying that a jack of all trades is a master of none... but I'm going to try to make this machine a good all around workhorse.  With that said, here is what I've purchased:

Case: Cooler Master Cosmos 1000

Power Supply: Corsair CMPSU-520HX

Motherboard: MSI P35 Platinum Combo

Video Card: MSI NX8800GT 512M OC GeForce 8800 GT

CPU: Intel Core 2 Quad Q9300 Yorkfield 2.5GHz

CPU Cooler: Scythe SCNJ-1100P

Memory: 2 X Corsair Dominator 2GB (2 x 1GB) 240-Pin DDR2 SDRAM DDR2 1066 (Total of 4 GB)

Optical Drives:

LITE-ON 20X DVD±R DVD Burner with LightScribe
LITE-ON Black 12X DVD-ROM 32X CD-ROM SATA Blu-ray DVD-ROM

Disk Drives:

2 x Seagate ST3500630AS 500GB 7200 RPM
WD1500ADFD 150GB 10000 RPM

Monitor: Samsung 2043BWX High Gloss Piano Black 20" Widescreen LCD 

Everything is currently on order, and will hopefully arrive next week.  I'm also considering what's on my old desktops that I might want to salvage.  For instance, I have an Adaptec 1394UW with some decently large SCSI drives, and a SCSI Zip Drive.  Is it worth hooking up?  I also have an IDE media card reader which will get hooked up as well.

My next post will be the build!

#    6:46 PM by Nick | 5 Comments |
 Monday, May 19, 2008

How Do You Type That?

On Saturday when I was out with the Cream City Flickr Group on a photo walk, I happened to take a picture of this sign outside of La Fuente, which if you don't know, is a fantastic Mexican restaurant in Walker's Point.

I Heart La Fuente

Now I remember that the "heart" character is in the extended ASCII character set, but can you actually type it in the address bar of a modern web browser?

Incidentally... their website is actually www.megustalafuente.com which I suppose is a close approximation to the sign in Spanish.

#    8:33 PM by Nick | 1 Comment |
 Wednesday, May 14, 2008

Quotable Twitter

From Jeff Atwood:

"How will this software get my users laid' should be on the minds of anyone writing social software (and these days, all software is)."

Isn't that the reason why men do anything?  To impress women?

#    8:39 AM by Nick | 1 Comment |
 Monday, May 05, 2008

Monday Music - Coulton Craze Edition

In honor of a fantastic Jonathan Coulton concert in Madison on Friday, I give you a Monday Music twofer!  First there is RE: Your Brains

And of course, I would be remiss if I didn't include Code Monkey.

That's the great part about his fan base... they are all perfectly willing to make his music videos for him with World of Warcraft.

I took a few pictures with my camera phone if you're interested.  It should come as no surprise that the crowd is very geeky, and almost everyone there was wearing "the uniform"... i.e. khaki's and a polo shirt.  And when Paul and Storm announced a giveaway for the first person who could show a 12 sided die, not only was there one person there with one, but it was a race between a dozen people to see who could get it out first.  And when Jonathan asked for a Mac Book power cable because he forgot his, there was actually someone there who had one to loan.

#    8:37 AM by Nick | No Comments |