title: Entity Framework Core Keyless Navigation Problem
body: <p>I'm building a proof of concept for my company. We have an existing platform that we will be replacing in pieces with modern technologies. Currently I'm restricted to using our existing databases which have several keyless tables. I'm building a Blazor WebAssembly application which is calling to a .net core web application using gRPC. My problem is I'm using EF Core to communicate with the existing databases but I get an exception when calling <code>DbContext.Attach(shipment)</code></p>
  
  <pre><code>"The navigation '' cannot be added because it targets the keyless entity type 'Document'. Navigations can only target entity types with keys."
  </code></pre>
  
  <p><code>Document</code> is a navigation property on the entity being <code>Attach</code>ed to the <code>DbContext</code>.</p>
  
  <p><code>Shipment</code> is a very large and complex data structure going many layers deep. Is there a way to avoid having to set the entity state for each entity, <code>DbContext.Entry(entity).State = EntityState.Added</code>, within the model's structure?</p>
  
  <p>Or possibly map the CRUD operations of the DbSet to stored procedures?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is a drastically shortened version of the schema, but this is all that is pertinent to the problem.</p>
  
  <pre><code>public class Shipment
  {
      public int Id { get; set; }
      // 60 other properties
  
      public virtual ICollection&lt;Document&gt; Documents { get; set; }
  }
  
  public class Document
  {
      public int ShippingId { get; set; }
      public string DocumentType { get; set; }
      public byte[] Content { get; set; }
  
      public virtual Shipment Shipment { get; set; }
  }
  </code></pre>
  
  <p>When I try to attach the <code>Shipment</code> entity to the <code>DbContext</code>, or manually set its state, I get the exception above. </p>
  
  <p>Again, I cannot change the database schema at this time and there are many other models similar to <code>Document</code> which do not have a key or a means of adding one.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I realize this needs further explanation. Obviously, the <code>DbContext</code> would not be able to Insert/Update/Delete since, without a key, it wouldn't know how. All I need is to be able to read when getting the <code>Shipping</code> entity and having the navigation property <code>Documents</code> be set. But when saving <code>Shipping</code>, just ignore the navigation property completely.</p>