title: .NET 4 EF4 insertint Unique Identifier into SQL Server table gives duplicates
body: <p>Hi I have an SQL Server table as below</p>
  
  <pre><code>CREATE TABLE [dbo].[Location](
      [LocationUID] [uniqueidentifier] NOT NULL,
      [Code] [char](10) NULL,
      [Type] [char](1) NOT NULL,
      [FullName] [nvarchar](150) NULL,
   CONSTRAINT [PK_Location] PRIMARY KEY CLUSTERED 
  (
      [LocationUID] ASC
  )
  ALTER TABLE [dbo].[Location] ADD  CONSTRAINT [DF_Location_LocationUID]  DEFAULT (newid()) FOR [LocationUID]
  </code></pre>
  
  <p>I have a C# WCF service in .NET4 using EF4 to insert into the Table location. This is the code that does it</p>
  
  <pre><code>  //create country
                  country = new Location()
                  {
                      FullName = CountryName,
                      Type = "C",
                      Diaretics = CountryName,
                      Code = CountryCode
                  };
                  dbContext.AddToLocations(country);
                  dbContext.SaveChanges();
  </code></pre>
  
  <p>But when I run the service the code falls over at dbContext.SaveChanges() with Error</p>
  
  <p>Violation of PRIMARY KEY constraint 'PK_Location'. Cannot insert duplicate key in object 'dbo.Location'.
  The statement has been terminated.</p>
  
  <p>I thought this is impossible to happen with the way the default value is set on LocationUID field with NewUID() and the configuration of primary key.</p>
  
  <p>Any help would be appreciated</p>