mha.dk

Random thoughts of wisdom - the personal blog of Michael Holm Andersen

ViewData and the null-coalescing operator

If you’re using ASP.NET MVC and are using the ViewData collection you might want to familiar yourself with the ?? operator.

The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.

Knowing this we can use the below syntax to e.g. display the title of a page in the browser with a value from ViewData and if this is null instead display a default value.

<%= ViewData["title"] ?? "Home Page" %>

MSDN has more info about the ?? operator.

Nice way to show off swimsuits

Take a look at http://avanteswim.com/09 if you want to see a creative use of Flash and video to sell / show off Avantes swimsuite collection of 2009

Google Calendar checker

Just a quick note: If you’re using Google Calendar, make sure to install the latest (BETA) version of Chrome and install the Google Calendar Checker :-)

chromecalextension

Enable Hibernate In Windows 7

My new Windows 7 install would not hibernate (which is really a nice feature, especially when hibernation is awesome fast using a SSD disk).

Anyways, after a bit of fiddling I found the solution – to enable hibernation do the following:

1. Open Command Prompt (with Administrator rights if UAC is enabled).

2. Next, type: powercfg /hibernate on

3. Close the Command Prompt .. you now (maybe!!) is able to hibernate (I was not)

… so if you can’t see the Hibernate option in Start menu then:

4. Launch Power Options from Start menu / Control panel

5. In the left pane, open the link labeled “Change when the computer sleeps” and then open the link “Change advanced power settings”.

6. Under the Advanced Sleep options, expand the Sleep tree and turn off Hybrid Sleep.

… and now in the Start menu you should see the Hibernate entry.

Chrome now support Extensions

…at last – Chrome Extension support is active and I for one have missed Xmarks synchronization (which luckily is one of the first to be released). Find your favorite extension at:

https://chrome.google.com/extensions

Windows 7 Libraries - Using network share locations

By default Windows 7 will not let you use a network share in “Libraries” unless it is either available offline (which kind of deny the purpose of a network share!) or it is indexed.

However, using some good old DOS/Shell tricks you can easily use network shares in “Libraries” anyway .. here how:

1. Create a folder on your hard drive inside c:\temp
2. Create another folder in the above folder called i.e. “myData” (c:\temp\myData)
2. Link the Library to this folder.
3. Delete the “myData” folder
4. Use the mklink in an elevated command prompt to make a symbolic link. Name the link the same as the folder you created above.
i.e - mklink /d c:\temp\myData \\server\myDataShare
5. Done. Now you have non-indexed UNC path as a library.

Google by default using “personalized search”

Google have changed the way they show their search results. In “the old days” (about a week ago!) Google only showed personalized search results if you were logged into your google account.

However this have changed. Google now always (even when the user is not logged in) now uses personalized search. If you’re working with SEO this – of course – changes the way things work (but that another story!), however .. when working with SEO you of course DO NOT want Google to use (show) personalized search (results).

So in order to turn this “feature” off we need to do this:

1. Go to WWW.GOOGLE.COM

2. Do a search

3. In the upper left corner, click the “Web history” link

4. Click the link “Disable customizations based on search activity.”

That’s it .. you’re now back to the “good old days” :-)

Assign a Shortcut Key to the Snipping Tool in Windows Vista

This one is mostly for myself (a reminder to do this on all my PCs):

http://www.howtogeek.com/howto/windows-vista/assign-a-shortcut-key-to-the-snipping-tool-in-windows-vista/

Cool 1920x1200 wallpaper

If you’re looking for a nice wallpaper for your 24” (1920x1200) monitor and are a bit tired of all the Windows 7 “art-deco” type wallpapers, take a closer look at this:

colour-wood-flip

A coloured (kind of RGB) wood – the original image is in 1920x1200 – click to download:

InvalidCastException on linq DB submit with non-integer key – aka LinqToSQL bug

Wasted a whole day on a (confirmed) bug in LinqToSQL. The problem is this:

“When database contains two tables, both with automatic integer primary keys, and a relationship between a unique char field in one and a non-unique char field in the other, inserting new rows into the second table fails on submit with InvalidCastException"

The error returned be LinqToSQL is: specified cast is not valid

I have a table which contains a char column which is ForeignKey to a unique char column in another table. In my case the column is “CurrencyISO” (e.g. the value DKK) in one table which has a FK relation to a unique ISO4217_ISO column in my Currency table.

Running on my development machine (Windows 7, x64) the code executes without problem – however running on my development server (Windows Server 2008 Web edition, x64) LinqToSQL at random (more or less!) throws the exception: specified cast is not valid

After having spend hours on the bug (I thought it was related to different OS and/or differences in MS SQL Server or something other “weird”), I found this article on Microsoft Connect which confirms the bug and the message “I can confirm that this bug has been fixed for .NET 4.0, which is why it's still failing with .NET 3.5 SP”

However a hotfix is available (and it will fix this bug!) – You can download yourself from Connect or if you’re running an x64 OS (Vista and/or Windows Server 2008), you can simple download the below .ZIP file which contains the hotfix (I’ve installed this on my Windows Server 2008 Web edition (x64), rebooted (an IIS reset should be enough!) and finally the bug was gone!!

Grab the hotfix (NDP35SP1-KB963657-x64.exe) for x64 platforms here: