# Monday, 25 February 2013

NuGet 2.2.1

NuGet 2.2.1 was released on February 15, 2013. The VS Extension version number is 2.2.40116.9051.

This release/update fixes 5 bugs. Here is a link to the issues fixed: http://nuget.codeplex.com/workitem/list/advanced?keyword=&status=Closed&type=All&priority=All&release=NuGet%202.2.1&assignedTo=All&component=All&sortField=LastUpdatedDate&sortDirection=Descending&page=0

It is sometimes hard to find release notes on these updates, so here is a link.

Link: http://docs.nuget.org/docs/release-notes/nuget-2.2.1

#    Comments [0] |

Productivity Power Tools 2012 – February 2012

A new update to Productivity Power Tools 2012! This update includes a couple of bug fixes including a crashing bug in the Custom Document Tab Well on debug. Download now!

Link: http://visualstudiogallery.msdn.microsoft.com/3a96a4dc-ba9c-4589-92c5-640e07332afd?SRC=VSIDE 
Download: ProPowerTools.vsix

#    Comments [0] |
# Tuesday, 27 November 2012

Visual Studio 2012 Update 1 is available

Microsoft has just made good on its promise of frequent updates to Visual Studio. The first update for Visual Studio 2012 is now available for download.

Somegar has done a nice blog describing the new features in this update: http://blogs.msdn.com/b/somasegar/archive/2012/11/26/visual-studio-2012-update-1-now-available.aspx

Or jump straight to the download at: http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update

#    Comments [0] |
# Sunday, 02 September 2012

Entity Framework 5 + Enumerations => What’s not to love?

Entity Framework 5 now supports enumerations (when using Visual Studio 2012 and targeting the .NET 4.5 framework).

So let’s have a look. We’ll create a table called Planet with a name and a field to indicate whether it is habitable.

CREATE TABLE [dbo].[Planets](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](max) NOT NULL,
    [Habitable] [smallint] NOT NULL,
 CONSTRAINT [PK_Planets] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END

Note: the data type for ‘Habitable’ is a smallint.

Next we’ll generate an entity data model from the database. Nothing exciting, since our database has just one table.

image

When we inspect the properties of the ‘Habitable’ property we see that, as expected, it is mapped to an Int16 (short).

image

Instead of a short we want to map the field to the following enumeration (note that having the enumeration be of type ‘short’ is significant, the type you select for your enum needs to match the column type in the database):

public enum HabitableEnum : short
{
  Humanoids = 1,
  Insects = 2,
  Droids = 3,
  None = 4,
  All = 5
}

In order to so, we need to update the model with information about the enum. This is done in the Model Browser.

image

Look for the “Enum Types” node and right click to add an Enum to the conceptual model.

image

We can have a locally defined enumeration (to be used in the T4 code generation) or we can refer to the previously defined enumeration by checking the “Reference external type” checkbox.

After adding the enumeration to the model we can now go and update the “Habitable” property in the conceptual model, the enumeration will now be displayed in the type listbox.

image

If we now browse through the generated code (click the triangle next to the Edmx file in your solution explorer) you’ll see that the generated class for “Planet” is now using the enumeration.

public partial class Planet
{
    public int Id { get; set; }
    public string Name { get; set; }
    public EF5Demo.Xyz.HabitableEnum Habitable { get; set; }
}
Should you not see the change, then right click on <yourmodelname>.tt and choose “Run Custom Tool” in order for the T4 template to regenerate the classes.

We can now write some code to insert and query the database. Here is an example:

var ctx = new StarWarsEntities();
Planet p1 = new Planet() { Name = "Tatooine", Habitable = HabitableEnum.Droids };
Planet p2 = new Planet() { Name = "Coruscant", Habitable = HabitableEnum.Humanoids };
 
ctx.Planets.Add( p1 );
ctx.Planets.Add( p2 );
 
ctx.SaveChanges();
 
var query = from p in ctx.Planets
            where p.Habitable == HabitableEnum.Humanoids
            select p;
 
foreach ( var p in query )
{
  Console.WriteLine( p.Name + " - " + p.Habitable );
}
 
Console.ReadLine();

When we run it:

image

That’s all there’s to it. Using enumerations with Entity Framework 5.

But wait, would it not be nice if we could use byte based enumerations and assign multiple values of the HabitableEnum to a planet?

Lets modify the enumeration to use the Flags attribute:

[Flags]
public enum HabitableEnum : byte
{
  Humanoids = 0x1,
  Insects = 0x2,
  Droids = 0x4,
  None = 0x8
}

We need to change the type of the ‘Habitable’ column in the database to a tinyint and we need to modify the information in the conceptual schema to inform the entity framework of our change in design:

image

The screenshot shows that we need to change the underlying type as well as check the “Set Flags attribute”.

We can now write code that assigns multiple values to the habitable field:

using ( var ctx = new StarWarsEntities() )
{
HabitableEnum x = HabitableEnum.Humanoids;
x |= HabitableEnum.Insects;
 
Planet p1 = new Planet() { Name = "Tatooine", Habitable = HabitableEnum.Droids };
Planet p2 = new Planet() { Name = "Coruscant", Habitable = x };
 
ctx.Planets.Add( p1 );
ctx.Planets.Add( p2 );
 
ctx.SaveChanges();
 
var query = from p in ctx.Planets
            select p;
 
foreach ( var p in query )
{
  Console.WriteLine( p.Name + " - " + p.Habitable );
}
 
Console.ReadLine();
}

The output looks like this:

image

If you wish to query for just insects you need to write a bitwise AND statement, like:

var query = from p in ctx.Planets
            where ( p.Habitable & HabitableEnum.Insects ) == HabitableEnum.Insects
            select p;

That’s all folks, have fun!

#    Comments [2] |
# Thursday, 16 August 2012

Windows 8 RTM and Visual Studio 2012 now on MSDN

For those of us with an MSDN subscription: Windows 8 RTM and Visual Studio 2012 are both available for download. Go to https://msdn.microsoft.com/en-us/subscriptions to get your copy.

 

image

#    Comments [2] |
# Wednesday, 29 February 2012

Microsoft Visual Studio 11 Ultimate Beta

Microsoft Visual Studio 11 Ultimate Beta has just become available for download. Go to http://www.microsoft.com/download/en/details.aspx?id=28975 to download the bits.

#    Comments [0] |