Linq to SQL, aggregates and empty results

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/9/2/f/appelgren.org/httpd.www/blog/wp-content/plugins/wp-syntax/wp-syntax.php on line 383 Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/9/2/f/appelgren.org/httpd.www/blog/wp-content/plugins/wp-syntax/wp-syntax.php on line 383 Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/9/2/f/appelgren.org/httpd.www/blog/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Hopefully I’m not the only one having trouble with aggregates, Linq to SQL and empty results. The query I had was something like the following.

var result = (from v in db.Table select v.IntColumn).Max();

This fails with an exception if Table is empty.

The null value cannot be assigned to a member with type
System.Int32 which is a non-nullable value type.

So after some reading on MSDN I found the extension method Queryable.DefaultIfEmpty, it returns a collection with one element that has the default value of the type of the IQueryable<T> if the IQueryable<T> is empty, that looked like it could solve my problem. But I quickly found out that it is not supported by Linq to SQL.

Could not format node 'OptionalValue' for execution as SQL.

So then after reading a blog post about this I ended up with the following query that does what I want.

var result = (from v in db.Table select (int?)v.IntColumn).Max()
    ?? 0;

It has the side effect that the generated SQL query contains an extra nested select but I think that is acceptable.

SELECT MAX([t1].[value]) AS [value]
FROM (
    SELECT [t0].[IntValue] AS [value]
    FROM [Table] AS [t0]
) AS [t1]

Yet another sync attempt

Some time ago I gave up on scheduleworld. I tried using Plaxo that synced to Microsoft Outlook and from there to my phone for a while but it was just to cumbersome. I had hoped that Plaxo would launch a SyncML solution, but that doesn’t seem likely for the foreseeable future.

Now I’m trying GooSync that currently only syncs with Google Calendar, but they recently announced that they were adding Google Contacts sync the next month or so. A big advantage of GooSync compared to Plaxo is that they handle events that you were invited to and support syncing multiple calendars, although to sync more calendars that the default you have to pay. But I don’t really mind that as long as the price is right, and GooSync is pretty cheap.

So now all I need is for Plaxo to add support for Google Contacts sync. Then I can sync my contacts and calendar wirelessly wherever I am to my phone and get contact updates from Plaxo. Maybe it’ll happen, but I wont hold my breath.

Gmail j2me for SE p1i

Some time ago Google started to detect my p1i on the download page for the mobile gmail app. Unfortunately the p1i version does not work correctly on a p1i phone. No fullscreen and the back button does not work.

Fortunately it looks like the version for SE k750i works correctly on SE p1i. I got it using the following URL:

http://gmail.com/app/gmail.jad?make=Sony%20Ericsson&model=K750&ver=v1.5.0.1187&hl=en

Update 20080409: The above URL is now broken, and Google has fixed the fullscreen issue with the P1i version of Gmail j2me but not the back button.

First Bioshock crash

Just experienced my first crash in Bioshock. Apparently it’s not a good idea to take a photo of a little sister just after you’ve rescued her. 😉 Most likely that was just a coincidence, but now I have to replay quite a lot.

Why can’t I send a crash report from my Xbox 360 as is possible in Windows when applications missbehave?

Confusing error from MsiMsp.exe

Had some trouble creating a patch with MsiMsp.exe version 4.00 yesterday.


ERROR: Cannot overwrite patch '%TEMP%\~PCW_TMP.TMP\tempcopy.msp'. Check the permissions to make sure that patchwiz will have access to the file. (Note, this path cannot be a folder.)

The mistake I had made was pretty simple, but the error message above sent me in the wrong direction when trying to solve it. I thought there was a problem creating the temporary file, silly me. The issue was instead that the directory where I wanted the output msp file to be created didn’t exist.

Done playing Oblivion

Finished all the quests that give you achievements in Oblivion yesterday, and a lot more side quests along the way. I’ve been playing the game off and on since it came out with probably somewhere close to 300 hours total playtime. Sounds pretty crazy, but I sure got my moneys worth. 🙂

I skipped over most of the dungeons and ruins unless I had to enter them because of quests since they were so boring and repetitive. Also, since everything leveled with you all sense of progress was lost. What I did spend my time on was the quests and books in the game. I loved the Shivering Isles and Dark Brotherhood quests. The main quests that involved the gates to Oblivion were really boring though. There was nothing in Oblivion to discover, only lava and some really repetitive towers to climb.

MsBuild item evaluation surprise

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/9/2/f/appelgren.org/httpd.www/blog/wp-content/plugins/wp-syntax/wp-syntax.php on line 383 Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/9/2/f/appelgren.org/httpd.www/blog/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Solved a problem with a build script last week. I had somehow caused the build to under some conditions take a very long time to start with heavy disk IO. After reviewing some recent changes I found the cause.

I had a ItemGroup that looked something like the following.

<ItemGroup Condition="'$(PathProperty)'!=''">
    <SomeItem Include="$(PathProperty)/**/*.dll"/>
</ItemGroup>

Apparently MsBuild evaluates all ItemGroups even if the condition of the group or item evaluates to false. The result is just discarded if the condition evaluates to false. So the item above included all dll files on the entire hard drive when PathProperty was not set. By trial and error I found out that the condition of Choose elements are evaluated before the items they contain.

So to speed things up I changed the above to the following.

<Choose>
    <When Condition="'$(PathProperty)'!=''">
        <ItemGroup>
            <SomeItem Include="$(PathProperty)/**/*.dll"/>
        </ItemGroup>
    </When>
</Choose>

Is this behaviour obvious to everyone else? Couldn’t find anything about it while reading the conditions documentation nor the documentation on items and properties on MSDN.