Lately I have really been getting stuck into MVC3. Initially I wasn’t convinced. The big reason for me wanting to avoid MVC3 was that Webforms provided the perfect solution for having to maintain state across postbacks, something that drove me crazy in the old days. Back then I was doing websites in Perl and JSP’s and it was a nightmare. But with MVC3 you lose all of the lovely viewstate stuff (btw, don’t let anyone tell you that viewstate sucks – if they say that they’re doing it wrong). But now I’m starting to learn jQuery, and things are looking up. I still hate javascript, it still feels like playing in a sandpit with a bunch of 2 year olds, but it can be pretty powerful.
I would say though that the benefits of MVC3 can’t really be attained without a bit of JQuery. I remember 10 years ago trying to write client side validation on the web, and boy it was painful. JQuery and the validation library (that actually works) both make all of that pretty good these days.
I’ve also been using the entity framework, and I’m starting to like it. Yes it gives you less control, yes you can create horrible SQL, but it can save you a lot of time. You can always default back to SQL for bigger queries, but for the simple CRUD I’m starting to love the entity framework. Combining it with AutoMapper (automapper.codeplex.com) and now you’re getting somewhere.
Today I wanted to come across a better solution for converting a List of objects from TypeA to TypeB. Previously I was doing something like:
Listthings = GetFromDatabaseOrSomething(); List otherthings = new List (); if (otherthings != null) { foreach (ClassA thing in things) { ClassB other = new ClassB(); other.propertyA = thing.PropertyZ; other.propertyB = thing.PropertyY; otherthings.Add(other); } }
That’s pretty long winded. But here’s a nicerer way:
Listotherthings = (things == null) ? null : things.ConvertAll(x => new ClassB() { propertyA = x.PropertyZ, propertyB = x.PropertyY });
That’s more like it! Sure it’s a bit more obscure, but really, it’s pretty simple.
So I’m almost up to date with all of the latest microsoft.net frameworks. What are the main ones that I’ve missed?