Saturday, December 18, 2010

Model View View Model Template: The MVVM Light Toolkit

I was catching up on my pod casts last week caught a great one on Hanselminutes featuring Laurent Bugnion discussing Model-View, View-Model (MVVM).  Laurent did a great job of describing MVVM in this cast and I recommended it to all who would like a sound grounding in MVVM.  My thanks to them both.

During the cast Laurent mentioned a number of MVVM frameworks, including his own called MVVM Light Toolkit.  I've been checking it out and like what I see so far.  In particular I love the EventToCommand behavior class available in the GalaSoft.MvvmLight.Extras library.  If I'm reading this right this lib will allow you to convert WPF events to commands.  This addresses one of my biggest complaints about doing MVVM with WPF.  The MVVM "ideal" is no event code in the code behind, but this is tough because many of the WPF components don't have command capability built in to them & frankly you need many of the events in order to craft a functional UI.  Hopefully this lib will deal with this lack.

I will be checking this out more throughly in the coming weeks & will let you know how usefull this turns out to be.

Tuesday, December 7, 2010

Quick Tip: LINQ Queries Require Optimization Too.

Recently I was asked by a colleague to look at a poorly performing LINQ query that was taking an unreasonable amount of time to execute (> 3 min). It didn't require much investigation to see that the query needed reordering of its joins and limiting of the elements returned. Once we rearranged the joins (inner joins first!) and limited the elements returned in the select, the query times dropped to under a sec.

This made me review some of my own LINQ queries and sure enough I had often made the same mistakes as my colleague did.  I bet if you review your own LINQ queries you may find the same issues.

Lesson learned by me today?   You should take care of how you form your LINQ statements.  LINQ is just different enough to make you lose sight of the fact its a query language.

See my earlier post on SQL query optimization. The tips outlined in this post will apply to LINQ queries as well.