Skip to main content

Software Development Stuff, July 2011

VS2010 Integrated SVN

I have recently discovered the AnkhSVN Visual Studio add-in for linking Visual Studio 2010 to your SVN repositories - it's fantastic:

Full Visual Studio 2010 integration - gives you those nice neat “checks” and other icons in the solution explorer, to indicate modifications, new items, etc. It's just like a bought one!

Data Access, Entity Framework 4.1, POCO

Have also recently discovered Entity Framework version 4.1 for awesome POCO (i.e. "code first") support - doesn't quite "just work" off the bat, but it's pretty damn close:

Couple of hints - initially, I kept on getting the following error message:

System.Data.SqlClient.SqlException: Invalid object name 'dbo.Users'.

...obviously I've got a table called [User]. There seems to be some issue (probably not an issue, but just my not reading enough about the framework) with pluralisation. Anyway, the solution is easy – decorate the EF POCO class with the TableAttribute:

 namespace Infostructure.SimpleList.DataModel.Models
[Table("User", Schema = "dbo")]
public class User
{ ...

JSON Serialisation with EF and AutoMapper

In the piece of work I'm doing a the moment (an MVC app that manages a bunch of “simple lists”) I want to be able to serialise to JSON where an incoming GET request is not ASP.NET authenticated and a UID and PW has come through on the query string.

Ran into trouble immediately with serialising my EF POCO objects to JSON, as they have circular references. So, I'm translating to ViewModels. Basically if I don't translate to my matching ViewModels, then I get ye olde "A circular reference was detected while serializing an object of type" exception.

Enter the fantastical AutoMapper library.

I use AutoMapper to handle the mapping from EF POCO objects to my ViewModels. The Mapper needs to be configured in the Global.asax ideally, or alternatively, just anywhere prior to where you intend to do the mapping. Like so:

 AutoMapper.Mapper.CreateMap<DataModel.Models.SimpleList, Models.SimpleListViewModel>();  

Here's some code from an Index method in one of my Controllers:

     public ActionResult Index()
string userName = Request.QueryString["userName"];
string password = Request.QueryString["password"];
if (User.Identity.IsAuthenticated)
_simpleListRepository = new SimpleListRepository();
var simpleLists = _simpleListRepository.GetSimpleLists(User.Identity.Name);
return View("Index", simpleLists);
else if (userName != null && password != null)
_simpleListRepository = new SimpleListRepository();
var simpleLists = _simpleListRepository.GetSimpleLists(userName, password);
var simpleListsDto = AutoMapper.Mapper.Map<IEnumerable<DataModel.Models.SimpleList>, IEnumerable<Models.SimpleListViewModel>>(simpleLists);
return Json(simpleLists, JsonRequestBehavior.AllowGet);
return View("Index");

Here's the link to AutoMapper:

That's all for now.

The code samples I've provided, etc, are a bit rough-and-ready as usual. However, should you happen to have stumbled on this post, and end up following some of it's recommendations, then I hope you enjoy using these features/tools as much as I have!

======= EDIT - 2011-08-01 =======

Unfortuantely AutoMapper uses Reflection.Emit, which is not allowed in a Medium Trust environment (i.e. my shared hosting web host).

There is an alternative out there called ValueInjector, which is not quite as complete-a-tool as AutoMapper as far as I can tell and has a bit of a steeper learning curve. Apparently it can be used in a Medium Trust environment:

I've reverted to a custom mapping implementation for the time being, since what I'm doing right now is not DTO-intensive. AutoMapper is great though and ValueInjector looks interesting.

======= EDIT - 2011-08-01 =======


  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    IPhone App Development| Android apps developer


Post a Comment

Popular posts from this blog

HOW-TO: Add/edit a field in Team Foundation Server 2012 using Visual Studio 2012

It's been a while since I made a purely technical post...

So, today I wanted to make a change to a Microsoft Team Foundation Server 2012 (TFS2012) instance that I am working with to reflect "Actual" time spent on a task - mainly for reporting purposes, and because I have found in the past that making this minor process adjustment yields a relatively useful metric over the long-term.

I am using the Microsoft Scrum 2.1 Process Template ( for a project that I am working with. So that I don't forget how to do this (again!) I will blog-post the procedure I've used to add this field to the template as a screen-shot-based tutorial, as follows...
Before Assuming you are familiar with the Scrum Process Template (2.1-ish) - open a task and take a look at the "Details" section, as follows:

 This is where I want my "Actual" field to show up.
Get the Power Tools Download and install the latest v…

HOW-TO: Apply a “baseless merge” in Team Foundation Server 2010 (and 2012)

Another purely technical post on TFS...
The scenario We wish to migrate code between branches that do not have a branch/merge relationship, in order to expedite urgent changes being made by a project team, without disrupting on-going BAU development work. Sample branch hierachy/strategy Imagine the following branching strategy in TFS (visible by connecting to TFS via Visual Studio 2010 or 2012):

Essentially you have a "DEV" branch, which has a "QA" branch, which in turn has a "PROD" branch. DEV is the branch that you would be using for BAU development. As a piece of development matures, you move it into QA, where it is tested by your internal QA team. There may be further changes made in DEV that are moved into the QA branch as the QA team pick up issues. Once the QA team are happy with a packaged of changes, they will move them into PROD, which is essentially the hand-over to the customer. The PROD branch represents the software that the customer has.


Eclipse/Android error: "Multiple dex files define [...]"

Wow, I am really going nuts blogging this-evening - 2nd post in less than an hour. 

Anyway this is a particularly nasty error that I keep running into with Eclipse/Android when starting the emulator after I have not run it for a little while. Since I run the risk of permanently forgetting the solution to the problem every time I walk away from my Android project (and thus having to spend a painful hour-or-so digging up the procedure again), I will blog it here, for my benefit, and for the benefit of anyone who may also suffer the same problem.

The gist is that when you start the emulator in debug mode (that is, you hit the button in the following image), you get the following error message come out on the console and a nasty popup telling you nothing more than there is an error with your program and you need to fix it:

[2012-04-06 23:20:57 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/gson/ExclusionStrategy;
[2012-04-06 23:20:57 - SimpleList] Conversion to Dal…