Pages

Wednesday, 8 July 2009

Current Reading List

These are the books I currently have open (on my desk, on my floor, on the window sill - you get the picture)...
Not enough hours in the day!

Saturday, 4 July 2009

Entity Framework: First Impressions

I have been working my way through Julie Lerman's book 'Programming Entity Framework' (review to follow) in order to evaluate the technology. On the face of it it seemed the perfect replacement for part of our existing solution that leveraged, the rather delapidated, SQLXml.

The concepts and patterns of the model seem absolutely spot on - very encouraging. However...

The EDM UI Designer that Microsoft has shipped is not even Beta 1. It seems that every change / customisation I make to my model is accompanied by a caveat. For example:
  • "Remember that if you make the base class abstract and then extend it you'll receive a compilation error. That's OK."
  • "If you want a '0 or 1'-to-Many relationship, first add it as a 1-Many, then setup your mappings then, finally, change the relationship back. Otherwise the designer breaks."
  • "You'll need to manually edit the SSDL Xml for this to work."
One of the really neat features of EF is the way it will sync with any changes to your underlying data source. Unfortunately, any manual changes you make to the conceptual layer are lost every time you update the model!

Secondly, the automatic code-behind generation leaves much to be desired. I think I read that this can be re-configured, but I shouldn't have to. Each Entity comes with its own Factory method. I would like this in a separate, static class please. I would also like it to instantiate a Builder class to do the work.

Finally, the exceptions. I appreciate that I am new to the framework but the errors (normally relating to Mapping Fragments) require the developer to wade through xml. Not good.

Overall, I want to use this framework but I'm loathed to give it the thumbs up. Hopefully, VS2010 will have a working designer?

Wednesday, 10 June 2009

Using Technology to Compensate for Lost Convection Currents

Working remotely has massive benefits that have been lauded for eons: no commute, flexible working hours, progressive working practices yada, yada yada; but it also has some major drawbacks. The main one that's been gnawing at me recently is the lack of Convection Currents of Information.

Being physically surrounded by like-minded developers (in an office) exposes you to these convection currents. You can't help overhearing John talking about the new API he discovered, or Sarah arguing with Mike about which Pattern would best solve problem X. When you work from home all you get is silence.

The great thing about these currents is that they are usually exciting, challenge you to change the status quo and stop you resting on your existing methodologies. It can be difficult to keep your saw sharpened if you lack day-to-day peer interactions.

I recently upgraded my phone to a cool new Windows Mobile device. The inbuilt RSS hub is now full with dozens of blog- and podcast-subscriptions that I can access anywhere, anytime. This is revelationary! Today I read Joel's post: 12 Steps to Better Code whilst out in the garden with the dog. Fantastic. And so little effort involved! I am no longer required to be at my desk if I want to learn.

And that really is the key: I needed a no-brain, easy solution to keep in touch with my peers and what they are doing today.

Just because you work remotely doesn't mean you can't be part of the conversation.

Tuesday, 9 June 2009

Polymorphic Limitations in Strongly-Typed ASP.Net MVC Views

Strongly-typing your views gives you nice, easy access to what ever view model your controller passes to it. Simple and powerful.

Unfortunately, though, there are some limitations.

  1. Your View Model cannot be abstract.
  2. Your View Model will only get POSTed back as itself.

The first point is fairly simple. Everything works until you POST back your view model e.g.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(MyAbstractViewModel model)
{
    // Clever bits go here...
}

Calling this action will result in the framework throwing a MissingMethodException: Cannot create an abstract class.

The second point is a little more complicated. Let's say you have 3 classes:

public abstract class MyAbstractViewModel
{
}

public class ViewModel1 : MyAbstractViewModel
{
}

public class ViewModel2 : MyAbstractViewModel
{
}

Now you create a simple GET Action that returns a View (strongly-typed to MyAbstractViewModel).

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{
    MyAbstractViewModel model;

    if (something)
        model = new ViewModel1();
    else
        model = new ViewModel2();

    return View(model);
}


The view will render successfully. Unfortunately, our original POST Action will not receive either of the concrete classes - only the one the view is explicitly typed against (i.e. MyAbstractViewModel).

These are, obviously, not major issues but it does limit developers' creative freedom and the most elegant solution may have to be foregone in order to fit the framework.

Thursday, 21 May 2009

Oi Microsoft, this IS part of Development!

I've hit a rather frustrating wall whilst implementing my Build Server for TFS 2008. As a company we have licenses for TFS 2008, VS2008 Development Edition and VS2008 Database Edition. Note the absence of VS2008 Test Edition (this is important!).

Our dev branch of source control is using a Continuous Integration model and builds the entire application on every checkin. Marvellous. However, I have been struggling to get the build to run (and report on) Code Coverage as part of the Unit Tests.

Turns out that you need to have VS2008 Test Edition installed on your build server. WTF!? Firstly, why should I need any client-side applications installed on my server for it to work (you need VS2008 Developer Edition to run Unit Tests as part of the build)? Secondly, why is Code Coverage considered part of the Test Edition? As a developer, a core part to producing good software is Unit Testing - which is worthless without a measure of Code Coverage!

Come on Microsoft. You've got to give us proper tools if you want us to continue developing for your platforms. Hopefully, life will change with VS2010?

Many thanks to Buck Hodges for responding to my emails and helping clarify the situation.

Session Availability in ASP.Net MVC

We are in the process of porting one of our Web Forms apps to ASP.Net MVC. This is just something we stumbled upon...

this.Session is null in a Controller's constructor.

Not a huge issue as you can use a Lazy Loading Pattern to circumvent it. It does raise the question of 'why?' though. The MVC (or Routing) framework is responsible for newing-up your Controllers to handle requests. Why couldn't Session be spun up prior to this?

Tuesday, 5 May 2009

LINQ to SQL only goes so far.

I have just finished re-writing my ailing photography website. I have taken the opportunity to write it afresh using ASP.Net MVC and LINQ to SQL. Whilst the latter is hugely more sensible than programming against a database it did highlight a flaw quite early on.

'Entities' in LINQ to SQL (i.e. database tables / views) are connected to each other via Associations. These map 1-1 with the Relationships in your database. Unfortunately, you can't customise these objects thus denying the developer and means to filter entities. Example:

I have 2 main entities in my application: Albums and Photos. An Album can contain many Photos and a Photo must be part of one, and only one, Album. I then added an IsExcluded property to the Photo entity. Unfortunately, I can't set the Association between the 2 to recognise this filter.

Solution 1: Create a new View called 'IncludedPhotos' and use that in the domain model.
Solution 2: Move to LINQ to Entities.