I recently had a task which involved modelling data from SQL Server into reasonably complex POCOs (plain old C# objects). Rather than adopt an ORM to enforce the relationship between the database and the POCOs, I decided to use LINQ to model the data into the correct form.
If we take these two data model classes below:
We notice that there is a one-to-N relationship between the Product class and the Asset class. There is an intimated many-to-many relationship between assets and products here – in the sense that a photographic asset can be linked to many products – but this is not enforced. Rather than implementing a full scale object relational mapper (ORM) solution to tying up the database to the POCO, LINQ’s GroupBy can be used in combination with a sub GroupBy query to first group by product code (there may be several entries in the table for each product code depending on how many assets are linked to the Product), and then group by asset ID a second time to pull in assets that appear across multiple products.
In an effort to expand my knowledge, I’ve decided to use some of my week nights after work to learn some other programming languages. Working as a .NET developer is sometimes a bit of a bubble – there is so much to know across the .NET ecosystem and often the underlying building blocks of the web are abstracted out and hidden under the hood of the framework itself that it’s sometimes easy to forget how the web actually works. So, with that in mind, I have decided to focus on other web-based languages – each month I’m going to focus on one particular programming language. I’ve settled on a fairly comprehensive list, which can be seen below:
Scala w/ Play framework
Java w/ Struts
PHP w/ Zend or maybe CakePHP
The coming posts will recap over some little experiments I’ve conducted in each language.
So it’s that time of the year again – the MB Interactive Bake Off series continues. This time around the contest is dedicated to our graphic designer, Paul “Minnsy” Minns. Entries into the competition will be judged on the Minnsyness factor – presumed to be not quite as good as the X Factor. As usual, I have prepared a fairly shoddy entry to the contest. I decided to design a Photoshop cake – I started with a bog standard cake mix by Betty Crocker and adorned it with the Photoshop logo. Not rocket science I’m afraid. The cake was made and looked like this undecorated:
Then I went a bit crazy with the iceing and ended up with this:
Overall, as someone who is not very artistic and has no discernable baking skills, I’m very happy with the result.
Recently I built an interactive real-time map on top of the (fairly) new Twitter Streaming API – in order to keep the stream to the API open, I used the C# Tasks library to process the connection to Twitter. One problem I encountered was that often web exceptions would occur in the lifetime of a task dedicated to streaming. I created several custom “watcher” classes to notify me when an exception occured. What I didn’t know at that point in time is that you can handle exceptions thrown by Tasks in a try/catch block as below:
// Assume this is a user-entered string.
// Use this line to throw UnauthorizedAccessException, which we handle.