Posts

Showing posts from June, 2012

AutoMapper: UseValue vs ResolveUsing vs MapFrom

I just hit a confusing mapping bug whilst using AutoMapper  to map DateTime.Now to a field in my database. Every item that was being added to the database had the same value in the "DateAdded" - to the millisecond. This was because I was using the following mapping expression: Mapper.CreateMap<SourceObject, DestObject>() .ForMember(m => m.DateAdded, o => o.UseValue(DateTime.Now)); UseValue() retrieves a value on first-run and stores it in the mapping (hence the static DateTime value that's being stored in the database), whereas ResolveUsing() resolves at run-time - which is obviously why it's called Resolve Using(). A minor oversight, but confusing nonetheless. Use ResolveUsing(s => {}) when you want to resolve a destination field from a derived value. This should be used for any DateTime mappings, and any more complicated mapping functions. Use MapFrom(s => s.MemberName) when you return an actual source object member. Use UseValue() if you...

IMDB API Lookup JQuery Plugin

I spent a few hours last night writing my first ever JQuery plugin, only to realise today that it's completely useless to me! I wanted an easy way to populate the "Add medium" form on RustyShark , as it tends to take me a few hours every time I add a new review (and therefore medium) to the website (y'know, looking up information, finding images, finding box art, editing the review etc), and I wanted to increase my production rate :) IMDB offers its data for free, for non commercial use, but only in text files. I found an API at http://www.imdbapi.com/ , which has gone a long way to simplifying and serializing the information in to something useful, so I decided to use this opportunity to teach myself how to write JQuery plugins. Below is my resulting plugin, queryable by Title + Year, or IMDB ID: ; (function ($) { $.fn.imdbLookup = function (options) { // Default options var defaults = { complete: function (imdbData) { ...

RustyShark.com is finally online!

Regular readers will know that I've been working on my new game and film review site for a good while now. I've been spending my spare time in the past few weeks editing the reviews I've written and gathered from friends, which has been a task in itself. Unfortunately, because the site is a bit of a movie and game database as well as a review site, it takes me a while to gather all of the information for each one, so I've not been able to launch with too many published! Suffice to say, I've got a lot more to get through, but when I've caught up I should be able to edit and publish reviews as they come in. All of the reviews I've received will be dealt with ASAP! I've still got a long way to go until version 1 of the site is completely finished. I still have to write the news editing tools and there are lots of additional features I want to implement, like a Facebook login, more products from different sites and RSS feeds. Of course, I've still got ...