Read this if you don’t know the “why” behind Guid.Comb. In a nutshell. We want to uniquely identify records and don’t want PK collisions across database instances. Using Guid as a PK used to be taboo. Now (circa 2002) it’s acceptable with Guid.Comb. It generates Guids in a semi-sequential order to limit page splits. This post is a combination of this and this.
What I’m using:
- EF 6 beta3 – Though you could probably use EF5 without issue
- VS2012 – Express should work
- SQL Express
1. Create a new Console App called GuidComb
2. Open Package Manager Console and run the following:
PM> Install-Package EntityFramework -Pre
3. Add this code to your app:
4. Run the following in Package Manager Console
5. Run the following in Package Manager Console
PM> Add-Migration Comb
6. Open the /Migrations/[Timestamp]_Comb.cs that was created by the Add-Migration command and add defaultValueSql: “newsequentialid()” to the Item table Column builder.
7. Hit F5 and you should see this:
As you can see the Guid are being generated sequentially.