title: LINQ to SQL Repository pattern auto increment problem
body: <p>I have weird problem and I'm trying to figure out whether it is my code or something has been messed up with database. I have a table WebClienteLogin which has an attribute Id (primary key, auto increment). I'm inserting new record when user registers on the website. </p>
  
  <p>Yesterday morning the value Id of the last registered user reached around 9000 and in the afternoon it started to jump in a funny way, so the next user had Id 1200, 25000 ..... and it reached 290000. However, today it continues as normal (incrementing by 1). From the statistics I see it happening when there is a big amount of users registering at the same time. </p>
  
  <p>Technologies used: SQL Server 2008 R2,ASP.NET MVC2, .NET 3.5</p>
  
  <p>I'm using Repository pattern with LINQ. Here is my implementation of one of my repositories.</p>
  
  <pre><code>public SQLWebClientLoginRepository(string connectionString)
  {
                  dataContext = new DataContext(connectionString);
                  tabla = dataContext.GetTable&lt;WebClientLogin&gt;(); 
  }
  
  
  public bool Save(WebClientLogin user)
              {
                  bool success = true;            
  
                  try
                  {
                      if (user.Id == 0)
                      {
                          tabla.InsertOnSubmit(user);
                      }
                      else if (tabla.GetOriginalEntityState(user) == null)
                      {
                          tabla.Attach(user);
                          tabla.Context.Refresh(RefreshMode.KeepCurrentValues, user);
                      }
                      tabla.Context.SubmitChanges();  
                  }
                  catch
                  {
                      ......
                  }
  
                  return success;
       }
  </code></pre>
  
  <p>Also the user has other object attached so it does INSERT into two tables and LINQ wraps it into transaction.</p>
  
  <pre><code>  var user = new WebClientLogin();
    // assigning other properties
    user.WebClient = new WebClient { // setting propeties }
  
    webClientLoginRepository.Save(user)
  </code></pre>
  
  <p>In log I get exception:</p>
  
  <p>An attempt was made to remove a 
  relationship between a WebClientLogin and a WebCLient 
  However, one of the relationship's foreign keys 
  (WebClient.WebCLientLogin_id) cannot be set to null." exception</p>
  
  <p>I have no idea why is it doing that! Anyone experienced anything similar?</p>