title: Sql mapping problems
body: <p>I have <code>CustomDBContext</code>:</p>
  
  <pre><code>public class CustomDBContext : DbContext
      {
          public CustomDBContext(string connectionString)
              : base(connectionString)
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              base.OnModelCreating(modelBuilder);
  
              ......
              modelBuilder.Entity&lt;KeyProd&gt;().ToTable("KeyProd");
              ......
          }
      }
  </code></pre>
  
  <p>And Repository registration in Startup.cs:</p>
  
  <pre><code>.....
  var builder = new ContainerBuilder();
  builder.Register(c =&gt; RepositoryFactory.GetInstance&lt;KeyProd, long&gt;("ef")).As&lt;IRepository&lt;KeyProd, long&gt;&gt;().InstancePerRequest();
  </code></pre>
  
  <p>After injection of this repository to my service, i try to add new row to database:</p>
  
  <pre><code>_keyProductionRepository.Add(new KeyProd
                          {
                              Id = key.Id,
                              Comment = key.Comment,
                              CreatedBy = adminId,
                              DateCreated = DateTime.UtcNow,
                              KeyType = key.KeyType,
                              PageId = key.PageId,
                              Name = key.Name
                          });
  </code></pre>
  
  <p>The exception is: 
  <em>Cannot insert the value NULL into column 'Id', table 'ln_resources.dbo.KeyProd'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.</em></p>
  
  <p>The model i try to insert have id (3). Is not null.I checked it in debug mode.</p>
  
  <p>My table in SQl without autoincremented Id. This is a query of table:</p>
  
  <pre><code>CREATE TABLE [dbo].[KeyProd](
      [Id] [bigint] NOT NULL,
      [Name] [nvarchar](100) NULL,
      [KeyType] [int] NOT NULL,
      [Comment] [text] NULL,
      [PageId] [int] NOT NULL,
      [CreatedBy] [int] NOT NULL,
      [DateCreated] [datetime] NOT NULL DEFAULT (getdate()),
      [DateUpdated] [datetime] NULL DEFAULT (getdate()),
      [UpdatedBy] [int] NULL,
  PRIMARY KEY CLUSTERED 
  (
      [Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
  )
  
  GO
  
  ALTER TABLE [dbo].[KeyProd]  WITH CHECK ADD  CONSTRAINT [FK_KeyProd_Page] FOREIGN KEY([PageId])
  REFERENCES [dbo].[Page] ([Id])
  GO
  
  ALTER TABLE [dbo].[KeyProd] CHECK CONSTRAINT [FK_KeyProd_Page]
  GO
  </code></pre>
  
  <p>My <code>KeyProd</code> Class:</p>
  
  <pre><code>  public class KeyProd
      {
          public long Id { get; set; }
          public string Name { get; set; }
          public KeyType KeyType { get; set; }
          public string Comment { get; set; }
          public int PageId { get; set; }
          public int CreatedBy { get; set; }
          public DateTime DateCreated { get; set; }
          public int? UpdatedBy { get; set; }
          public DateTime? DateUpdated { get; set; }
      }
  </code></pre>
  
  <p>If i try to insert this model directly from <code>SQL SERVER</code> by using <code>SQL INSERT</code>, all works fine. 
  Where the problem? Why Id is Null? Why mapping not working.</p>