title: Debug blackbox DbContext.SaveChanges() when it doesn't
body: <p>I have a very simple sample program to begin to get to grips with the reality of Entity Framework 5. I have read a fair amount of theory and everything seems good but immediately I run into a problem with saving to a database. </p>
  
  <p>The problem I have is that DbContext.SaveChanges() is neither throwing an exception (which i expected) nor saving the data.</p>
  
  <p>Heres the code:</p>
  
  <pre><code>     public class PhysicalAddressType
          {
              [Key]
              public long AddressTypeIndexCode { get; set; }
  
              public string TName { get; set; }
  
              public long ClientId { get; set; }
  
              public Guid UserId { get; set; }
  
              public DateTime LastModified { get; set; }
  
  
          }
  
          public class TestContext : DbContext
          {
              public TestContext() : base("Name=Basd.ContactManagement") { }
  
              public DbSet&lt;PhysicalAddressType&gt; Addresses { get; set; }
          }
  
       static void Main(string[] args)
              {
                  try
                  {
  
                      using (var ctx = new TestContext())
                      {
                          var ph = new PhysicalAddressType();
                          ph.ClientId = 500;
                          ph.UserId = Guid.NewGuid();
                          ph.TName = "test1";
                          ph.LastModified = DateTime.Now;
                          ctx.Addresses.Add(ph);
                          ctx.SaveChanges();
  
                      }
                  }
                  catch (Exception ex)
                  {
                      System.Diagnostics.Debug.WriteLine(ex.Message);
  }
          }
  </code></pre>
  
  <p>I expect the code to throw an exception because I have not provided a mapping to the table in the database. Here is the schema of the table:</p>
  
  <pre><code>CREATE TABLE [erp_crm].[PhysicalAddressType](
      [AddressTypeIndexCode] [bigint] IDENTITY(1000,1) NOT NULL,
      [TName] [nvarchar](50) NOT NULL,
      [ClientId] [bigint] NULL,
      [UserId] [uniqueidentifier] NULL,
      [LastModified] [smalldatetime] NOT NULL,
   CONSTRAINT [PK_PhysicalAddressType] PRIMARY KEY CLUSTERED 
  (
      [AddressTypeIndexCode] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  GO
  </code></pre>
  
  <p>But it doesn't and nor does it store a record in the database.</p>
  
  <p>So my question is how do I debug at this point? My first question would be whether it's even hitting the DB, not because the connection string is wrong (in app.config) but for some other reason. Is "silent failure" a real part of the EF experience?</p>