Sunday 30 December 2012

Entity Framework 5 - Auto incremental GUID columns

I started poking around Entity Framework 5 using VS 2012 Express edition.

One of the tests I wanted to do was to find out how EF5 handles auto-incremental GUIDs. So here goes...

Reproducing the problem


I will be using database-first model using SQL Server 2012 Express.


I have highlighted the important areas. Basically table has a "Status" column that is set to use "NewId()" binding. This will automatically create a Guid when a new row is inserted.

Thereafter a new conceptual model was created. (See below.)

Once the corresponding EDMX file is created, it will be opened in the Visual Studio editor by default. As there is only a single table in the database, one entity will be created.

Click on the "Status" scalar property to view its properties.


Keep a close eye on the "StoreGeneratedPattern". This properties is what EF uses to determine the value population strategy of the given column. The available options are "Identity" and "Computed".

We set the binding in the SQL Server to auto populate the "Status" column (NewId()). However when we add a new row to the table using EF, following is what we get.


This is most surely not that we want. The "Status" value is set to the default Guid value.

Fixing the issue

Actually the fixing the problem is pretty easy... What we need to do is to return to the conceptual model and update the "StoreGeneratedPattern" of "Status" property to "Computed" as below.


By updating the property to "Computed"; it notifies the EF that the value of the property is calculated by the store (in this case SQL Server).


Just watch out!

Tuesday 25 December 2012

Udacity CS101

I completed CS101 course offered by Udacity few days ago.

I must admit that I could not get every answer correct. This is the first time I am using Python and it opened a whole new avenue for me. It really sparked my curiosity with Python.

I highly recommend this course for anyone who is interested in learning computer science.

My certificate :-)

Saturday 15 December 2012

Playing with Windows Service Bus 1.0 !!

I started looking at Windows Service Bus and Google was giving me a ton of resources for Azure service bus. I want Windows Service Bus!!

I started by reading through this article. 

I managed to configure Windows Service bus using the instructions in this note. (See below).


I am using Windows 8 and using SQL Server Express 2012.

Once the installation was complete, I followed this note. One thing to note here is that the NuGet package name has changed from "Service Bus 1.0 Beta (for Windows Server)" to "Service Bus 1.0 for Windows Server".

I was unable to complete the exercise and the application was failing with an Authorisation failed  exception. 
However after playing with it for a bit, I managed to get it to work. The key to watch out are the Service Bus URIs. These can be found at the bottom of the dialog after configuring the Service Bus. (See below). 

The EndPoint is where the Service Bus is available at; and STSEndPoint is where the token for accessing the Queue is obtained. So... keep a note of these URIs. 

Code is here. (If you do look start looking at the code make sure to start the sender first and then the receiver.)