Entity Framework, Adding Data To Database
<p>We have a problem while we are trying all of the data to database. We are using Entity Framework Code First method and SQL Server. Our connections are ready, our tables have been created. </p>

<p>We are keeping our data into List right now. But we cant send it to database. Its our code. When code comes to Save.Changes line, it crushes</p>

<p><strong>ITS THE ERROR CODE</strong></p>

<blockquote>
  <p>An exception of type
  'System.Data.Entity.Infrastructure.DbUpdateException' occurred in
  EntityFramework.dll but was not handled in user code</p>
  
  <p>Additional information: An error occurred while updating the entries.
  See the inner exception for details.</p>
</blockquote>

<h1>CONTACT ENTITY</h1>

<pre><code>public class Contact 
{
    [Key]
    public int Id { get; set; }
    public string cn { get; set; }
    public string sn { get; set; }
    public string c { get; set; }
    public string l { get; set; }
    public string st{ get; set; }
    public string title{ get; set; }
    public string postalCode { get; set; }
    public string physicalDeliveryOfficeName{ get; set; }
    public long? telephoneNumber{ get; set; }
    public string givenName{ get; set; }
    public string initials { get; set; }
    public DateTime? whenCreated { get; set; }
    public DateTime? whenChanged { get; set; }
    public string co{ get; set; }
    public string displayName{ get; set; }
    public int? delivContLength { get; set; }
    public string company{ get; set; }
    public string proxyAdress{ get; set; }
    public string streetAdress{ get; set; }
    public string mailNickname{ get; set; }
    public string name{ get; set; }
    public int? primaryGroupID { get; set; }
    public string objectGUID { get; set; }
    public string objectSID{ get; set; }
    public string sAMAccountName{ get; set; }
    public string mail{ get; set; }
    public string homePhone { get; set; }
    public string mobile { get; set; }
}
</code></pre>

<h1>ENTITY FRAMEWORK PAGE</h1>

<pre><code>namespace WebApplication5.EntityFramework
{
    public class PhoneDexContext : DbContext

    { 
        public DbSet&lt;Contact&gt; Contacts { get; set; }
        public DbSet&lt;SyncInfo&gt; SyncInfo { get; set; }
    }
}
</code></pre>

<h1>DATABASE SECTION</h1>

<pre><code>namespace WebApplication5.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            var test = new LdapServiceManager().getAllUsers();
            var phoneDex = new PhoneDexContext();

            foreach (var contact in test)
            {

                //phoneDex.Entry(contact).State = System.Data.Entity.EntityState.Added;
                phoneDex.Contacts.Add(contact);

                //TODO HATA ALINIYOR
                phoneDex.SaveChanges();

            }

            return View();
        }    
    }
}
</code></pre>