title: Entity Framework Duplicate Entries and Auto Propertie filling
body: <p>I have the following two classes</p>
  
  <pre><code>[Serializable]
  public partial class DocumentType
  {
      public DocumentType()
      {
          this.Documents = new List&lt;Document&gt;();
      }
      public int ID { get; set; }
      public string Name { get; set; }
      public virtual ICollection&lt;Document&gt; Documents { get; set; }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>[Serializable]
  public partial class Document
  {
      public Document()
      {
      }
      public int ID { get; set; }
      public string FileName { get; set; }
      public byte[] Data { get; set; }
      public Nullable&lt;int&gt; TypeIDfk { get; set; }
      public virtual DocumentType DocumentType { get; set; 
  }
  </code></pre>
  
  <p>I make use of a Client-Server Architecture and using Sockets I send a list of all the DocumentTypes over the Network into a Combobox
  On SelectionChanged in the Combobox I set the 
  DocumentType = Selected DocumentType
  and Also the TypeIDfk to DocumentType.ID</p>
  
  <p>The Problem I have is when I send the Document over the Network back to the Server and it saves it into the Database it creates a Duplicate Entry into DocumentType. and then changes TypeIDfk</p>
  
  <p>I solved it by setting DocumentType = null ( but leave the TypeIDfk ), this is bad because of Binding I want to Display. also that doesn't bother me too much I can do the following
  TypeIDfk to DocumentType.ID
  Send and Save
  DocumentType = Selected DocumentType</p>
  
  <p>However this is where it gets funny.
  I did the following
  this.Configuration.ProxyCreationEnabled = false;</p>
  
  <p>Now after I called SaveChanges() when I inserted Document into the DbSet
  the Document.DocumentType gets filled Automatically. (even tho it was null)
  I dont want that I want to stay null after Inserted so I can change it again on ClientSide.</p>
  
  <p>But it would be great if Someone can help me solve the Issue on the Duplicate Entries.
  I have around 64 Classes for my project at university going through each Insertforms to check where duplicates rise will take me a week or more :/</p>
  
  <p>Thanks for any response</p>