title: Insert Not Saving Using EF 4.1 Code First
body: <p>I'm having an issue here that is blowing my mind. It's a very simple insert into a very simple table... something I've done a thousand times, but isn't working here for some reason.</p>
  
  <p>Basically, I'm running a simple INSERT (via the repository pattern) and then saving the context changes. There are no errors, I can step through it just fine, but the record just isn't in the database. </p>
  
  <p>In the interest of (hopefully) covering my butt against stupidity: I know I'm connected to the right database because it's fetching the seed data just fine (and there's only 1 connection string in my app). Also, I know the database isn't being rebuilt every time.</p>
  
  <p>Here is the calling code:</p>
  
  <pre><code>var result = new Core.Models.Poll
  {
      ElectionId = electionId,
      DatePublished = pubDate,
      DateCreated = DateTime.Now,
      NameEn = nameEn,
      NameFr = nameFr,
      Params = splitVals,
      Url = url,
      Slug = String.Empty
  };    
  
  Components.PollRepository.Insert(result);
  Components.PollRepository.Save();
  </code></pre>
  
  <p>And here are the methods in the repository:</p>
  
  <pre><code>public void Insert(Poll poll)
  {
      Context.Polls.Add(poll);
  }
  
  public void Save()
  {
      Context.SaveChanges();
  }
  </code></pre>
  
  <p>At the <code>Context.Polls.Add(poll);</code> line, I inspect my object... when I manually run an insert statement in SSMS using values in the poll, the record gets created with no problem. When I run <code>Context.Entry(poll)</code> at the next line (the <code>}</code>), then I see that it's State is Added (as expected).</p>
  
  <p>I'm running this using IIS Express on my local dev machine against SQLEXPRESS.</p>
  
  <p>Oh, and here's key of the Poll class (I tried that <code>DatabaseGenerated</code> attribute with no luck):</p>
  
  <pre><code>[Key]
  //[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int Id { get; set; }
  </code></pre>
  
  <p>Any help, or even anything else to try, is greatly appreciated.</p>