Emergency Calls, Locations and 55: The Truth

Reading Time: 3 minutes

You may well have seen this meme going around Facebook and other places. As a general rule, unless you can trace information like this back to an actual emergency service or other reputable outlet, you should assume that it’s fake.

In this case it’s inaccurate, but it does contain some information that’s true.

The Full Fact article does a reasonably good job of explaining, but I can add little more detail from a different perspective.

When you make a 999 (emergency) call in the UK, the emergency services have access to some extra information about that call that they don’t get for other calls. This happens automatically whether you dial 55 or not.

If you call from a land-line or telephone box, the emergency service has access to the subscriber details for that line. This includes the name of the person that the line is registered to and the address.

If you call from a mobile, the situation is a little more complex. The emergency service can request the location of the mobile phone – and usually does so automatically. That request gets passed to the mobile phone company. Before the days of GPS, the mobile company would return, if it could, an estimate of the location based upon the signal strength and the location of the cell masts nearest to the phone. It can sometimes provide quite accurate results, but other times it’s not so good.

The mast information is still sent to the emergency services. Now however almost every mobile phone has GPS so new methods have been developed so that the phone can also send its location data all the way through to the emergency service control room. Not every phone can do this, so you can’t rely on it, but the more time that passes, the more phones are coming on-board.

It’s worth noting that a mobile phone’s own location data isn’t always accurate. It’s usually pretty good, within a few metres, but there are a number of factors that can throw it off, sometimes by just a few metres, but I’ve seen examples of phones thinking they’re on a different continent.

Again, to be clear, you do not need to dial 55 or perform any secret handshake to make your location available. If your phone can do it, the mobile network can do it and the emergency service can do it, then your phone’s location data gets sent to the control room. It’s all automatic. This is what I think the meme is talking about as “new technology”. Otherwise, the mast data is almost always available.

Where dialling 55 comes in is if you’re in a situation where you can’t talk. If you’re hiding from an attacker for instance you might not want to talk as it may alert the attacker to your location. The mobile operator may well ask you to dial 55 if you’re there and are in danger. That’s the point of dialling 55 – it lets the operator know that, although nobody is speaking, you have not dialled 999 by mistake.

I should point out here that the emergency services do not always respond to silent 999 calls. They have to assess each call individually and decide whether to respond, whether the person talks or not.

Ultimately then there is some truth to the meme and I suspect somewhere, underneath it all, someone knew what they were talking about. It looks however as if it’s been through a few people and by the time the meme was made some of the messages have got a bit mixed up.

To conclude:

  • The emergency services can always get your location and usually do automatically. You do not have to dial 55 to make that happen.
  • The “new” bit is that the emergency services can now get the location data direct from many smartphones, instead of having to rely on mast data.
  • Only dial 55 if you are unable to speak for some reason. The operator may ask you to do this anyway if you don’t speak. If you can speak however, do.

Finally, don’t assume when you call that the emergency services do have your location. Things can go wrong, the more information you can give them over the phone, the better.


Tom Fosdick is a software engineer who is responsible for the system that several UK emergency services use to get 999 call locations.

I’m Pulling the Social Media Plug

Reading Time: 4 minutes

In the words of a certain radio station, “Social media can be a force for good, but it can also be a giant pain in the arse.”

When I wrote that First Class Post was the most rapid form of communication of which I approved I was only half joking. I recently spent two weeks in India. Rather than deal with the expense of roaming or hassle of a local SIM I just turned mobile data off. It was a surprisingly liberating experience.

It’s not like I dropped off The Internet completely: there’s free WiFi in most hotels and a few restaurants. What I found though was that having Internet access time-boxed had a far greater effect on the way I lived my life than I could ever have imagined.

I’ve spent pretty much my entire career in communications, most of it trying to improve the connectivity and communication technology used by the emergency services. I’d always kind of assumed that more connectivity and more flexible communications were a good thing.

It’s true – the increased ability to communicate can benefit us very greatly. For instance, we’re now talking about the ability for members of the public to stream video directly into an emergency service control room. That information could be hugely useful to the call-taker, in informing the member of the public, in informing the crews being sent to the scene and also providing an evidence trail for any followup action.

On the flip side however, as I’m sure you can imagine, the ability to stream video from a remote location to another, particularly via an end-to-end encrypted channel, facilitates some of the most appalling people in existence.

To a lesser extent the same is true of social media. It enables us to keep in contact with people that we would otherwise naturally lose touch with, but it also throws up conflicts that we would never otherwise have. On top of this the social media companies themselves aren’t making money unless you’re using them. They make every effort to ensure that their platform invades your life as much as possible.

Over the past year or so I’ve become utterly frustrated with this: I’ve disabled all notifications from every social media app on my phone. What India taught me however is that this isn’t enough. If I really want to take back control from social media, I have to remove myself from the social media environment and only step back into it on my terms.

Social Media is not a new thing, it existed back in the dial-up days. The difference was that to be online you had to make a phone call, and the costs could mount up if you weren’t careful. You had to set limits, for purely financial reasons (especially if you were on a trainee’s wage).

So I’m setting usage limits again.

Just before we left for India, my partner and I were in a restaurant and the couple next to us spent the entire meal on their phones. They barely talked to each other. The first rule therefore is:

No phones at the dinner table, wherever that dinner table is: in the house; in a restaurant; a picnic table in a field; etc.

If I’m out and about doing jobs or visiting people, the chances of me needing to call someone are fairly high, but the chances of me needing a smartphone are fairly low. The second rule:

Unless there is a clear reason to take the smart phone out, take the dumb phone [see above photo].

The penultimate rule I call the “Soap Opera Rule”. In many ways Social Media is like a Soap Opera, the two differences are that it deals with real people and that it’s constant, it doesn’t come in half hour chunks 3 times a week. The former is somewhat the point of Social Media. The latter is something that you have to manage and it helps if you think of it more like a Soap Opera:

Set clear daily usage limits and don’t exceed them.

Of course there are exceptions to every rule. When we’re talking about usage limits we have to consider what the purpose of usage is. If you’re organising a family meal via WhatsApp that’s not the same as reading your Twitter timeline.

The key here is be sensible and maintain perspective.

The last rule is the simplest of them all:

Talk to people.

Social media is no way to conduct a friendship. Sure, it’s a great way to allow you to find people with common interests and to keep touch with people who you would otherwise lose touch with. Those people aren’t your friends (although they may have been or may become so). Ultimately, friends are not people you broadcast status updates to. Friends are the people you have a conversation with when you have news.

So call them, invite them round for tea, go to lunch with them, go watch a film with them but interact with them directly and personally, not via timelines and group chats.

From now on I’m going to be following these rules. In reality you probably won’t notice any difference, but I think it’s going to make a big difference to me and I hope these words make a difference to other people.

Remember that it’s in the interests of the Social Media companies to create a society where it’s socially unacceptable not to be glued to your phone. Don’t sign your life over to them: take back control and always, always be true to yourself.

Poppies

Reading Time: 4 minutesA few years ago I took the very deliberate decision to stop wearing a remembrance poppy, because I actually believe in remembrance.

Take a look around social media in the few days around November 11th and you’ll see an awful lot of messages simply thanking military personnel for their service.

That is only half the message of remembrance. Not only that but without the other half it’s a dangerous message because it’s easily corrupted.

We sleep-walked into the First World War. The warning signs were there years before. They were noticed, alarm bells were rung, governments were advised: “unless we change course,” they were told, “there will be war”. The warnings were ignored and there was the most terrible war the world had ever seen.

The economic and social devastation of the First World War pretty much guaranteed the subsequent rise of populism, particularly in the hardest hit countries. That does not however mean that the rise of the Nazi Party was inevitable. They could and should have been stopped.

Martin Niemöller’s seminal “First They Came” highlights just one thing – that it was within the power of ordinary people to stop it. However we stood aside and did nothing and by doing so damned a whole generation.

Tens of millions died in two catastrophic wars, both of which were entirely avoidable.

For me that has always been the meaning of the phrase “Lest we forget…” We must remember the senseless waste of two generations. We must never again sleep-walk, or let ourselves be led as lambs into another unnecessary war.

If you want that put in transparent, soul-piercing clarity Siegfried Sassoon was there:

AFTERMATH

Have you forgotten yet?…
For the world’s events have rumbled on since those gagged days,
Like traffic checked awhile at the crossing of city ways:
And the haunted gap in your mind has filled with thoughts that flow
Like clouds in the lit heavens of life; and you’re a man reprieved to go,
Taking your peaceful share of Time, with joy to spare.
But the past is just the same,—and War’s a bloody game….
Have you forgotten yet?…
Look down, and swear by the slain of the War that you’ll never forget.

Do you remember the dark months you held the sector at Mametz,—
The nights you watched and wired and dug and piled sandbags on parapets?
Do you remember the rats; and the stench
Of corpses rotting in front of the front-line trench,—
And dawn coming, dirty-white, and chill with a hopeless rain?
Do you ever stop and ask, “Is it all going to happen again?”

Do you remember that hour of din before the attack,—
And the anger, the blind compassion that seized and shook you then
As you peered at the doomed and haggard faces of your men?
Do you remember the stretcher-cases lurching back
With dying eyes and lolling heads,—those ashen-grey
Masks of the lads who once were keen and kind and gay?

Have you forgotten yet?…
Look up, and swear by the green of the Spring that you’ll never forget.

Make no mistake, I am not a pacifist. There are times where war is the only practical solution. And of course I support The Royal British Legion and Help For Heroes, of course I have enormous respect for those who are prepared to lay down their lives to defend the free way of life.

There is a very important distinction however between the individuals who serve and those who would lead us into war. The latter, we must reflect, is substantially our fault: in a democracy we are the ones that set the agenda.

In remembrance it is therefore not sufficient simply to thank those who have given military service. We must take time to reflect on why their service – and in many cases sacrifice – was needed. We must reflect on our failure as the people of the United Kingdom, the people of Europe, to prevent two devastating wars and numerous conflicts since.

Moreover those who do not learn from history are doomed to repeat it. We can see, very clearly, where the mistakes that led to each war, each conflict were made. It is imperative that we learn those lessons.

Currently some of The Poppy’s most ardent supporters are far right groups. Far from being reflective and contemplative on the horrors of war, these groups delight in militaristic imagery and seek to glorify military conflict.

They even use The Poppy and the concept of remembrance to try to shut down their critics, “Your grandfathers!” they scream, “Your grandfathers didn’t give their lives so that…”

Economic stagnation breeds populism. Austerity breeds populism. Populism inevitably veers either toward communism or fascism. These are delicate times and we, those of us who are sufficiently well informed to understand this, have a duty to try to steer our countries away from those extremes.

This is why I don’t wear a poppy: because I believe that it is not an effective means of communicating how I feel about remembrance. Because most people just pin the badge on because they think they ought to without really understanding it. Because that lack of understanding is easily corrupted into support for very people that Remembrance was designed to condemn. Because I’m scared that as the generation that fought the Second World war dies out, the memory how of terrible, how devastating it was and why we must never allow history to repeat itself will die too.

Because I’m scared that we will wear The Poppy and tell ourselves that we have not forgotten when in truth we have.

C# Best Practice: Why a Separate “lock” Object?

Reading Time: 4 minutesSome time about 1995 I noticed that I was writing a lot more concurrent code than the other programmers. It was almost as if someone was deliberately pushing it in my direction… That theme never really changed.

I was rather surprised then when a developer made a comment on something I’d written a few years back, because I was pretty confident I’d covered all the bases.

public class SomeServer
{
    private readonly Dictionary<KeyType, ValueType> queries = new Dictionary<KeyType, ValueType>();

    //stuff

    public void PerformLookup(string someQueryTerm)
    {
        //some logic...
        lock(queries)
        {
            //some more logic
        }
    }
}

The comment was:

Please use a separate lock object. e.g. private readonly object _queriesLock = new Object();

Eh? What?

OK, hands up I missed this. I learnt to use basic concurrency tools way before C# existed. For me C#’s ‘lock’ construct was great because it allowed me a very clear and concise way to use a monitor. As far as I was concerned there was no downside. Why on earth would I want to use a separate lock object?

There are 2 things you need to be really careful about when using a lock in this way.

You must carefully manage the lifetime of the locked object.

Imagine above if ‘queries’ were not a readonly object created at instance initialisation. Imagine if someone did…

lock(queries)
{
    //stuff
    queries = new Dictionary<KeyType, ValueType>();
}

You have to make sure that the locked object is instantiated before the fist lock is taken out and you must make sure that it is not reassigned in any way until after the last lock has been exited.
If you don’t it leads to all different flavours of bad.

If you instantiate a separate lock object at object initialisation, an object that has no purpose other than as a lock, then you know it’s there at the start and the chances of someone messing with it before the end of the last lock are very significantly reduced.

You must be careful not to expose the locked object externally

C# allows an implicit monitor to be created on any object. You can use that monitor by wrapping the object in a ‘lock’ statement.

If you wrote the class to use, say a mutex explicitly rather than the implicit monitor there’s no way you consider making the mutex externally accessible…

public class SomeServer
{
    private readonly Dictionary<KeyType, ValueType> queries = new Dictionary<KeyType, ValueType>();
    public Mutex _queryLock = new Mutex();

    //stuff

    public void PerformLookup(string someQueryTerm)
    {
        //some logic...
        _queryLock.WaitOne();
        try
        {
            //some more logic
        }
        finally
        {
            _queryLock.ReleaseMutex();
        }
    }
}

That’s complete madness – any other class can mess directly with the lock and cause all sorts of unwanted behaviour. Deadlocks are a particular hazard here and compound deadlocks can be really tough to debug.

If you’re using the implicit monitor via the ‘lock’ construct however and you expose the locked object beyond the scope of the class, you are effectively also sharing the monitor.

public class SomeServer
{
    public Dictionary<KeyType, ValueType> queries {get; private set;} = new Dictionary<KeyType, ValueType>();

    //stuff

    public void PerformLookup(string someQueryTerm)
    {
        //some logic...
        lock(queries)
        {
            //some more logic
        }
    }
}

public class SomeOtherClass
{
    private SomeServer myServer=new SomeServer();

    public void SomeMethod()
    {
        lock(myServer.Queries)
        {
            //some logic
        }

        //or worse...
        Monitor.Enter(myServer.Queries)
        //and the Monitor.Exit is in another method that might not get called
    }
}

If you use a separate lock object that you know is private and will always be private then you don’t have to worry about this.

Having written this pattern many, many times in many different languages I’m not likely to fall into either trap. That’s not all that being a good developer is about though.

HwacheonCentreLathe 460x1000

Now, this might seem like a strange tangent but bear with me. I learnt to use an industrial [machine] lathe when I was a kid. They teacher drummed 2 things into us.

  1. Do not wear any loose clothing (e.g. a tie)
  2. Do not leave the chuck key in when starting the lathe

The reason these 2 things in particular were so important was because the lathe I learnt to use had no guard. Either of those 2 mistakes could be fatal.

I’m glad I learnt that, but given the choice would I use the lathe with a guard or the one without? It’s a no-brainer.

We have the same situation here. Unless we’re writing something very specific where memory is absolutely critical, there’s no harm in creating an extra lock object. It provides a useful safeguard against a couple of gotchas that could cause real headaches in production.

Software development purists will be wringing their hands, but they’re not what commercial software development is about. It’s about writing code that does the job in a simple, safe and maintainable way. That’s why using a separate lock object is C# best practice and that’s why I fully support it.

Cultural Erosion

Reading Time: 2 minutesCultural erosion is often cited as an argument against European Integration. A fortnight ago I was in a Belgian roadside café. They had three different types of mayonnaise in pump dispensers and a man sat eating moules marinière with a tiny bottle of rosé.

Britain has always been a bit special – and that’s not just British exceptionalism speaking. We have always been sailors, explorers; we are a diverse nation that includes cultural elements from all over the globe. It’s one of the things that make us strong.  The question we have to ask however is whether these cultures complement British culture or erode it.

The culture of Britain is under no substantive threat from other Europeans.

Every British town has a McDonalds, Pizza Hut, KFC, Subway and Starbucks. We watch Amazon Prime and Netflix, Nickelodeon, Warner Brothers, Disney, Discovery. We don’t eat moules marinière in roadside cafés, we eat Burger King. We don’t watch François Truffaut films, we watch 20th Century Fox Movies. The biggest threat of cultural erosion that Britiain faces is from the USA.

Remember:

  • Burgers are foreign food
  • Coke is a foreign drink
  • Hollywood is foreign cinema

Other European cultures aren’t immune either, they are more protected because of language but you still find American chains, American food, American films and TV wherever you are in Europe.

We can be much more effective in resisting cultural erosion, from wherever it comes, if Europe works together. The preservation and enhancement of European cultures is a specific objective of the European Union. Far from trying to homogenise European culture there are programmes in place trying to designate, protect and promote individual European cultures (and that includes British culture).

Yes, we are a bit special because we are an island. We mustn’t get carried away with that and think that our past, our present and our future is not inherently tied up with that of the rest of Europe, because it is. Europe is stronger if it acts together, Britain is stronger if it acts with Europe.

First Class Post

Reading Time: 2 minutes

Someone recently accused me of replying too slowly on WhatsApp. “First Class post” I replied, “is the most rapid form of communication of which I approve.” I wasn’t joking.

The fact that you’re not going to get a reply for at least 24 hours, if not the best part of a week, tends to rather focus the mind. You have to concentrate on exactly what you want to say, no more, no less and ensure that your communication is complete. There’s no “soz, not what I meant lol” if you botch what you were trying to say.

Writing someone a letter makes you value the communication.

I’ve never been comfortable with the telephone, I consider it a step too far. A letter arrives on your doormat. You might pick it up and open it immediately, or put it aside for later. It’s your choice. You can then think about your reply whilst you’re cooking or re-glazing the east wing.

The telephone however screams “STOP!” when it rings, “whatever you are doing cease it now! Someone wants to talk to you!” It’s just plain rude. On top of that it might not even be a conversation that you wanted to have at that time.

No, the telephone is an abomination and the mobile phone doubly so. There are numerous reasons why one might not answer a house telephone. There is no escape from the mobile, it’s there, in your pocket, constantly buzzing, continually demanding attention.

We now have so many ways of near-instant communication that we have lost all respect for the privilege that technology has brought us. Instead we spend every waking minute in cataclysm of indistinct missives trying to make sense of a world projected into our hands by people who are at best as misinformed as we are.

Don’t get me wrong, I’ve spent the past 20 years delivering ever-improving communication technology into the hands of our emergency services. I’m very much in favour of the technology.

I am more that happy that I have in my pocket a device that lets me communicate in a variety of ways with almost all of my family and friends, with businesses, government and even write articles like this that will be read by complete strangers.

I however respect the fact that I don’t know what the intended recipient of my communication is doing at that moment. I respect the fact that they may not want to reply immediately. I don’t believe it’s asking too much for that respect to be mutual.

One From The Vaults: Testing

Reading Time: 3 minutes

Looking for Rhino (real ones, not mocks)

Whilst I was looking for something else I found an explanation I wrote years ago to try to explain to senior management how testing had changed and become critical in the Agile environment. It’s not the easiest thing to try to get across: the business wants features that it can sell. I don’t think I did a bad job, so here it is.

Having now spent a few months with this project I’m very conscious that, at the moment, we don’t have much of a testing strategy. It looks as if we’re trying to offload all responsibility for testing onto the testing department.
This rather implies that our primary testing strategy is manual system testing.
Failed system tests are expensive – and if they impact promised delivery dates they can be a major problem. It would be better if we could have a good idea before we entered a system test whether or not it’s going to pass and that is a software quality management problem.

(Technical) testing should start in the software design. The questions the developers should be asking are;

  1. How am I going to achieve this task?
  2. How am I going to test it?

As an example, user interfaces are notoriously difficult to test, but if one of the MVC style design patterns is used it means that the view (the actual UI) can be separated from the rest of the code. This means you can write a program to test the logic behind the UI without having to try to actually click buttons programmatically.

There are any number of places within the design of software where adding a little thought to how it can be (easily or preferably automatically) tested is of significant advantage.
The more automated testing we can get in the better. If we can get to a position where a substantial portion of the code is automatically built and tested every night that would be great. It means that we, as developers, get continuous feedback about the state of the software.
We can then go into a system testing phase with a much higher level of confidence that it will pass.

This does mean however that we need to start investing in testing, which can be a difficult message to get across. If we don’t however then as the software and the functionality grows and the code-base becomes more difficult to maintain we will be taking ever increasing risks with the future of the product.

It’s a good idea to get this baked in now.

I would suggest that a feature is not finished unless the issue of how it is going to be tested is solved – and that means the automated tests and / or the manual tests written. If there’s no automated testing there needs to be an explanation of why.

The more bodges, work-arounds and spaghetti code there is, the harder it becomes to maintain and the longer it takes to develop each new feature. A product which leads the market can very quickly fall behind because every time someone tries to do something they have to try to unravel all the spaghetti, they then inevitably end up piling on more spaghetti just to make it work and making it worse for the next edit. Technical debt snowballs.

As with all things there’s a balance, I’m conscious we need to get features to market fast, but as the product matures the importance of testing will increase. Automated unit testing ensures that each building block of the project actually does what we think it should do. It’s not a silver bullet for solving all technical debt, but it’s a good starting point. Making code testable enforces certain good behaviours that will increase the longevity of the product.

I do not believe that the current development strategy is sustainable. I am therefore intending to phase in a plan that will, in time, see all new development covered by automated testing and will start to retrofit automated testing into the existing code-base. Inevitably this will slow down the speed we can get features to market, by a known and controllable overhead. Our business model is based on repeat business. If we fail to get a grip of technical debt the competition will overtake us in the mid term and it will invalidate that model.

Stop! Thief!

Reading Time: 2 minutes“That image looks awfully familiar” I found myself thinking when reading an article on vinyl record run-out groove etchings. Then it clicked, it was one of my images, reproduced in someone else’s article without my permission and with no recognition that it was my image.

Image of Vinyl Factory 29 Dec 2017

I’m not a professional photographer, it’s true I do know which end of a camera is the sharp one, but trying to make money out of photos is just more hassle than it would be worth to me. Consequently I’m quite happy for my images to be reused for non-commercial purposes provided that I’m given due credit.

What I do mind however is when my images get re-used on commercial, for profit sites without even so much as an acknowledgement. Even on commercial sites it’s really not worth me pursuing them for revenue (although I reserve the right to do so), what I mind is the fact that it’s downright rude not to credit the original artist.

There’s really no excuse for this – even if someone found the image on a different site a Google reverse image search will very quickly identify its origin. Consequently I have no hesitation in naming and shaming places where I’ve found my images used without my permission and without any recognition.

Original Article Rip Off
A Porky Prime Cut Vinyl Factory
And Twitter
A Porky Prime Cut Two Good Ears
A Porky Prime Cut jack.canalplus.fr
IP Webcam MSN / Auntie Acid
(image and factual content)
IP Webcam Auntie Acid
(image and factual content)
IP Webcam estisuperba.ro

And again (different article)

IP Webcam smalljoys.tv
Goodwood Cobra (racing) conboy.us
Goodwood Cobra (crash) conboy.us
Goodwood Cobra (crash) armeniabirding.info
Goodwood Jaguar D Type (racing) 165.227.181.117
Goodwood Jaguar D Type (rear) 165.227.181.117
Grand Rosela Hotel, adelynndesign.us

Entity Framework Double PK Overwrite Gotcha

Reading Time: 2 minutesI was writing some unit tests: largely out of completeness I wanted to test that you couldn’t insert two records with the same primary key. The code is simple enough.

    var car = db.Cars.OrderBy(g => Guid.NewGuid()).First();
    var pool1 = db.Pools.OrderBy(g => Guid.NewGuid()).First();
    var driverName1 = Guid.NewGuid().ToString().Trim('{', '}');
    var created1 = PoolAllocatedCar.Create(car, pool1, driverName1);
    db.PoolAllocatedCars.Add(created1);

    var pool2 = db.Pools.OrderBy(g => Guid.NewGuid()).First();
    var driverName2 = Guid.NewGuid().ToString().Trim('{', '}');
    var created2 = PoolAllocatedCar.Create(car, pool2, driverName2);
    db.PoolAllocatedCars.Add(created2);

    Assert.Catch<Exception>(()=> db.SaveChanges());

Car Id is the sole primary key of the PoolAllocatedCars table.

Being bit lazy I guessed it was quicker for me to run the code and find out what exception SaveChanges() it threw rather than trawl through the docs and work out what it should be.

The problem: it didn’t throw an exception. So I added some debug to find out what happened, the result is disappointing to say the least.

---===*** FAILED TO NOTICE PK CLASH ***===---

In Memory:
    Car Id [24] Pool Id [49] Driver [bda1d05c-8dae-4648-ab42-736eb8c44b71]
    Car Id [24] Pool Id [08] Driver [9dae73a0-5b8d-45bc-9d0a-f8b73141aa2c]

In Database:
    Car Id [24] Pool Id [08] Driver [9dae73a0-5b8d-45bc-9d0a-f8b73141aa2c]

It would appear that Entity Framework simply overwrote the first record with the second without giving any indication that there was ever a primary key clash.

Now I’m sure that somewhere in the documentation there’s a warning or a note about this but I haven’t found it yet…

Update: It Gets Worse

I was taken aback by the above, that it could be deemed acceptable to treat the explicit addition of a second object with the same primary key as an implicit update with no warning to the user.

I guess then I shouldn’t have been surprised that it even does this after an explicit call to SaveChanges()

The following test gives exactly the same result as the first. This is a massive gotcha.

    var car = db.Cars.OrderBy(g => Guid.NewGuid()).First();
    var pool1 = db.Pools.OrderBy(g => Guid.NewGuid()).First();
    var driverName1 = Guid.NewGuid().ToString().Trim('{', '}');
    var created1 = PoolAllocatedCar.Create(car, pool1, driverName1);
    db.PoolAllocatedCars.Add(created1);

    db.SaveChanges();

    var pool2 = db.Pools.OrderBy(g => Guid.NewGuid()).First();
    var driverName2 = Guid.NewGuid().ToString().Trim('{', '}');
    var created2 = PoolAllocatedCar.Create(car, pool2, driverName2);
    db.PoolAllocatedCars.Add(created2);

    Assert.Catch<Exception>(()=> db.SaveChanges());

The good news is that if you use a different DbContext it throws an exception :- in fact on the Add, not the SaveChanges.

I’m having trouble getting my head around this: I can’t see the logic. If you thought there was a chance that you’d want to update an object after you’d added it to the table then you should keep your own reference to it. If that’s a problem because of scope then your design is probably wrong.

The Jet Set

Reading Time: 4 minutesI really genuinely hate air travel. I will do pretty much anything I can to avoid it. I’ve taken a 16 hour train journey from Suffolk to Barcelona to avoid a 3 hour flight. It’s not that I’m afraid of flying, there’s just something about the whole experience that I find fundamentally unpleasant.

South Africa however is a bit of a trek. Personally I’m completely up for a McGregor/Boorman type epic, but there are certain logistical problems. Mainly not having anything like the spare cash that Ewan McGregor has. Or time. He does seem to have a lot of spare time.

Consequently I’m currently sat on a plane and I’ve been here a while…

There’s never anything on the entertainment system that I want to watch. I have no idea why. It could have my favourite show on there and I still wouldn’t want to watch it. I’ve gone through it all, pawed the duty free catalogue, scanned the in flight magazine and read the safety instructions twice. It’s half past midnight and I am still quite unreasonably awake. It’s at times like this when I conclude that it’s a good idea to listen to Pink Floyd’s Atom Heart Mother.

I’m almost coming to terms with “Alan’s Psychedelic Breakfast” when I suddenly become aware of something plasticky in front of me. I’m just about to “put it over my mouth and breathe normally” when my nose informs me that it’s curry. I conclude that I could in fact eat, not because I’m hungry but because I’m bored and I’m hoping that redirecting some of the blood supply from brain to stomach might help me at least doze.

To this end I order wine too, “Cabernet Sauvingon?”, I enquire. “No, but we’ve got Sauvingon Blanc”, comes the reply. “No thanks,” I interject, “Cabernet Sauvignon is a red” but it’s too late and an open mini bottle of white wine lands on my tray table. I note that is a Marlborough and decide that it’s better the devil you know.

Nevertheless my plan works and half an hour later I’m in the land of nod.

I awake to the rather uncomfortable realisation that I ordered Asian Vegetarian food on this flight. I usually do because it seems more difficult for airlines to murder curry then it does any other type of food. Unfortunately breakfasts can get interesting as I’m about to find out when I’m served bland, generic cheese, coleslaw and sort of bread that tastes like dehydrated semolina pudding.

On the bright side I conclude that breakfast service must mean that I got a good few hours sleep and that there can’t be that much time left on the clock. I don’t dare look however.

I fire up my music player and decide to give the Amaranthe album I curiously downloaded on Spotify a listen. The first track is good, but I very quickly conclude that although Euphoric Dance / Death Metal crossover might sound like an interesting and challenging concept, right here, right now it’s just very, very annoying.

Thankfully the entertainment system has some Chopin and my eyelids are starting to feel heavy again.

There’s an eerie silence when I wake and another strong smell of curry. Chopin has finished and my noise cancelling headphones are busy cancelling out the drone of 4 enormous GP7000 series jet engines.

I lift the lid on the tray in front of me: the airline chefs have surpassed themselves this time and reached a whole new level of achievement. Somehow they have managed to screw up a paneer curry.

Fortunately there are enough other dishes to make a meal. There’s even some spare cheese, just in case cheese in lightly spiced cream sauce wasn’t enough dairy for one meal.

By the time I’ve obtained a cup of tea I’m feeling brave. I’ve had two good sleeps and three bad meals. We must be nearly there, right?

3 hours to go. There’s nothing out the window but cloud. The aircraft cameras are showing nothing but cloud.

Now all we need is some… whoa! Where’s the floor gone? Is that kind of jolt within the tolerances this plane was designed for? “A bit bumpy”, why yes Captain I think we’ve all noticed that. There was a small hint in that if I hadn’t been wearing my seatbelt I’d be sitting in the overhead locker right now.
I then spend the next few moments marvelling at how, firstly, relatively minor atmospheric conditions can hurl a 500 tonne plane about like a piece of confetti and secondly what a superb piece of engineering it is that a 500 tonne plane can be hurled around like a piece of confetti without the wings falling off.
Now however the baby is screaming and the bloke next to me is pale as a ghost and clinging on to the arm rest for grim death.

I try to think of some words that might be of comfort to him, but everything I can think of either makes me sound like a smug git or contains the word “plummet”. I do however make a note to stop jokingly referring to our destination – a well known London airport – as “Splatwick”.

Still more than 2 hours to go but on the positive side, I’m starting to wonder if there’s some mileage in trying to write a blog article about why I hate flying so much…