# Thursday, October 17, 2013

Windows 8.1 available for download

Windows 8.1 is available for download and great news! It is free to anyone already running Windows 8.

Download available here: http://blogs.windows.com/windows/b/bloggingwindows/archive/2013/10/17/windows-8-1-now-available.aspx

#    Comments [0] |
# Thursday, June 27, 2013

Visual Studio 2013 Preview available for download

Interested in test driving the next version of Visual Studio? Download the Visual Studio 2013 Preview at: http://www.microsoft.com/visualstudio/eng/2013-downloads

#    Comments [0] |
# Thursday, June 06, 2013

NuGet 2.5.4

NuGet 2.5.4 has been released. With over 160 work items in this release the team felt they should skip version numbers 2.3 and 2.4. Checkout the release notes at http://docs.nuget.org/docs/release-notes/nuget-2.5.

#    Comments [0] |
# Monday, February 25, 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] |
# Saturday, February 16, 2013

Upcoming Events

Here are some events in which I’m involved or which are being organized by friends:

February 25, Maine Developer Network (Augusta, Maine): Two topics in this meeting: First What’s New in Entity Framework 5 and second Using NuGet and creating packages. More on: http://www.maine-devnet.org/Home/Meetings.aspx

February 26, Bangor Area .NET Developer (Bangor, Maine): Two topics in this meeting. First Windows Azure and second How to get free/cheap Microsoft software. More on: http://www.bangordevelopers.com/

March 18, SDN Event (Zeist, The Netherlands): A bunch of topics ranging from Delphi for iOS to Windows Azure to SOLID principles. More on: http://www.sdn.nl/SDN/SDNEvent/Events2013/SDNEventMaart2013/tabid/219/Default.aspx

#    Comments [0] |
# Tuesday, February 12, 2013

Deleting a project from Team Foundation Service

I ran into this today. We needed to delete a project from Team Foundation Service, but there is no way to do this through the UI. Luckily Buck Hodges wrote a post on this already. You need to use the command line TFSDestroyProject.exe tool and make sure to use the VS2012 version, not the VS2010. Also include ‘DefaultCollection’ when specifying the collection name.

Read more here: http://blogs.msdn.com/b/buckh/archive/2011/09/19/how-to-delete-a-team-project-from-tfs-on-azure.aspx

#    Comments [0] |
# Tuesday, January 29, 2013

Creating ASP.NET membership and authentication tables in SQL Server (Aspnet_regsql.exe)

There is a little command line tool that can create the standard ASP.NET membership and authentication tables in an existing SQL Server database instance. (Since I seem to have a hard time remembering the name of the tool I’d figure I’d write a little blurp on my blog to act as a reminder Smile ).

Aspnet_regsql.exe is a command line tool. You can run it without parameters to have it help you in via wizard mode, or apply the right parameters and do it commando-style. See http://msdn.microsoft.com/en-us/library/ms229862.aspx for available parameters.

And if you want to enable the ASP.NET Web Administration Tool on a test or production server, then this forum post http://forums.asp.net/t/932674.aspx/1 tells you how to do that.

#    Comments [1] |
# Wednesday, January 23, 2013

Speaking at Augusta Tech Talk

The invitations just went out: I’ll be presenting at Augusta Tech Talk on February 25th 2013. There will be 2 sessions; one about NuGet and one about Entity Framework 5.

For more information and registration got to: http://maine-devnet.org/Home/Meetings.aspx

#    Comments [1] |
# Monday, January 21, 2013

NuGet, Files and Source Control

I’ve been using NuGet for years, but recently I’ve been playing with around with NuGet to try and explore some of the lesser known features. I’ve just been using NuGet to effortlessly download and add assemblies to my projects, but where do these files go? And how do I make sure that when I zip my sources and send them to another developer, that person also has everything he needs? How does NuGet play with regards to source control?

Default NuGet Workflow

The default process when using NuGet to install a library (for example EntityFramework) in your project is as follows:

  1. Start a new project in a new solution and add the solution to source control.
  2. Open the Package Manager Console.
  3. Type: “install-package EntityFramework”
  4. At solution level NuGet creates a folder named ‘Packages’.
  5. NuGet determines the most recently, non-beta, available version of EntityFramework and downloads this file into a folder, named after your package in the ‘Packages’ folder. It also creates a ‘repositories.config’ file to keep track of which projects are using NuGet. The folder may look something like this: 

    image

    Note that all the files in the ‘Packages’ folder and it’s subfolders are automatically added to source control.
  6. NuGet adds a packages.config file to your project and uses this to keep track of which packages and versions are installed in the project:

    image
  7. When you now check into source control all configuration information as well as all the downloaded packages are preserved and managed in source control.

The default approach works well in most scenarios, but has one downside: if you have a lot packages in your solution, then the size of your source control branch may become larger than desired. This would be less of an issue with say Team Foundation Server, but more of an issue with a DVCS like Mercurial or Git.

Restore During Build Workflow

An alternative approach is offered by using the Enabling Package Restore During Build option. Read the tutorial here to see how it is done.
There are three differences with the default NuGet workflow:

  1. A .nuget folder is added to the solution, which contains NuGet.exe, a config file and a build file. These file will be added to source control upon check in.
  2. Downloaded NuGet packages in the ‘Packages’ folder (they’re still there) are not added to source control.
  3. Every time you (re)build your project the NuGet build step will check to make sure the appropriate NuGet packages have been downloaded.

Zipping projects

As a rule: whenever you want send someone the sources of a project that uses NuGet for maintaining library references, make sure you send the solution, including the packages folder. If you’re using the Restore During Build Workflow, then the zip does not need to contain the actual packages.

#    Comments [0] |
# Tuesday, November 27, 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, September 02, 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] |
# Sunday, August 26, 2012

Entity Framework 5 is available

Entity Framework 5 is included in Visual Studio 2012, but is also available to users of Visual Studio 2010 (as a NuGet package: http://nuget.org/packages/EntityFramework/ ).

Note: Some Entity Framework 5 features are only available when writing an application that targets .NET 4.5. This includes enum support, spatial data types, table-valued functions and the performance improvements.

Read more about what is new on the MSDN ADO.NET blog: http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx

Update [08-27-2012] : Julie Lerman has an excellent post describing the difference between running EF5 in a .NET 4 versus a .NET 4.5 application, read more on: http://thedatafarm.com/blog/data-access/when-entity-framework-5-ef5-is-not-entity-framework-5-ef5/

#    Comments [1] |
# Thursday, August 16, 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] |
# Monday, April 30, 2012

String literals and ‘==’ versus Equals(…)

I had a little fun today playing with ‘==’ vs. the Equals(…) method. I knew that somewhere in .NET 2.0 (I believe) there had been some improvements in String.Empty versus “”, but I didn’t quite realize that this affected all string literals.

In the code below you can see how value types and reference types may behave differently when using ‘==’ versus the Equals method.
My surprise came when I discovered that line 39 and 41 both return TRUE. Apparently the string literals in an assembly get put in a master list of string constants and then reused where the same string literal gets used. Nice!
The way to force the reference comparison of the string against object to actually be different is to delay the creation of the string until runtime, like in line 52.

   1:  static void Main(string[] args)
   2:  {
   3:   
   4:      // value types
   5:   
   6:      int x = 10;
   7:   
   8:      int y = 10;
   9:   
  10:      Console.WriteLine( x == y );  // compare by value -> return true
  11:   
  12:      Console.WriteLine( x.Equals( y ) ); // compare by value -> return true
  13:   
  14:      Console.WriteLine( object.ReferenceEquals( x, y ) );  // compare by reference -> return false
  15:   
  16:   
  17:      Console.ReadLine();
  18:   
  19:      // Reference types
  20:   
  21:      StringBuilder s1 = new StringBuilder( "yes" );
  22:   
  23:      StringBuilder s2 = new StringBuilder( "yes" );
  24:   
  25:      Console.WriteLine( s1 == s2 ); // compare by reference -> return false
  26:   
  27:      Console.WriteLine( s1.Equals( s2 ) ); // compare by value -> return true
  28:   
  29:      Console.WriteLine( object.ReferenceEquals( s1, s2 ) ); // compare by reference -> return false
  30:   
  31:      Console.ReadLine();
  32:   
  33:      // object and string
  34:   
  35:      object o1 = GetName();
  36:   
  37:      string o2 = "Mark";
  38:   
  39:      Console.WriteLine( o1 == o2 );  // compare by reference -> return true
  40:   
  41:      Console.WriteLine( o1.Equals( o2 ) ); // compare by value -> return true
  42:   
  43:      Console.WriteLine( object.ReferenceEquals( o1, o2 ) ); // compare by reference -> return true
  44:   
  45:      Console.ReadLine();
  46:   
  47:   
  48:      // object and string
  49:   
  50:      object ss1 = "Mark";
  51:   
  52:      string ss2 = "Markx".Substring( 0, 4 );
  53:   
  54:      Console.WriteLine( ss1 == ss2 );  // compare by reference -> return false
  55:   
  56:      Console.WriteLine( ss1.Equals( ss2 ) ); // compare by value -> return true
  57:   
  58:      Console.WriteLine( object.ReferenceEquals( ss1, ss2 ) ); // compare by reference -> return false
  59:   
  60:      Console.ReadLine();
  61:  }
  62:   
  63:  static object GetName()
  64:  {
  65:      return "Mark";
  66:  }
#    Comments [4] |
# Wednesday, February 29, 2012

Windows 8 Consumer Preview

ISO images with the Windows 8 Consumer Preview are now available for download. Go to http://windows.microsoft.com/en-US/windows-8/iso to get the bits.

#    Comments [3] |

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] |
# Tuesday, January 24, 2012

Type-Safe Include extension method for Entity Framework

If you’re interested in the Include method in a LINQ to Entities queries to be type-safe, then Joe Ferner has the answer for you in this post: Type-Safe Entity Framework Include: http://www.nearinfinity.com/blogs/joe_ferner/type-safe_entity_framework_inc.html

#    Comments [0] |
# Tuesday, January 17, 2012

Generating an index in the database using Entity Framework Code First

If you’re using Entity Framework Code First, then you may want to create an index on some of your table. The way to do this is to call “Database.ExecuteSqlCommand” in the “Seed” method of your database initializer. The sample below shows how it is done (thanks to Rolf for pointing me in the right direction):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
 
namespace CodeFirstPlayground
{
  class Program
  {
    static void Main( string[] args )
    {
      Database.SetInitializer<CodeFirstSampleModel>( new CodeFirstSampleDbInitializer() );
 
      using ( var model = new CodeFirstSampleModel() )
      {
        var query = from c in model.Customers
                    where c.Name != null
                    select c;
 
        foreach ( var item in query )
        {
          Console.WriteLine( item.Name );
        }
      }
 
      Console.ReadLine();
 
    }
  }
 
  public class CodeFirstSampleModel : DbContext
  {
    public CodeFirstSampleModel()
      : base( "CodeFirstSampleDB" )
    {
      Customers = this.Set<Customer>();
    }
 
    public DbSet<Customer> Customers { get; set; }
 
  }
 
  public class CodeFirstSampleDbInitializer : DropCreateDatabaseAlways<CodeFirstSampleModel>
  {
    protected override void Seed( CodeFirstSampleModel context )
    {
      context.Database.ExecuteSqlCommand( "CREATE INDEX IX_Customer_Name ON Customers (Name) " );
      
      Customer c = new Customer()
      {
        Name = "Mark",
        LastOrder = DateTime.Now
      };
 
      context.Customers.Add( c );
 
      base.Seed( context );
    }
  }
 
 
  public class Customer
  {
    [Key]
    public int Id { get; set; }
    [Required]
    [MaxLength( 50, ErrorMessage = "Customer name must be 50 characters or less." )]
    public string Name { get; set; }
    
    public DateTime? LastOrder { get; set; }
  }
}
#    Comments [3] |