title: EntitiyFramework retrieving and storing back entities
body: <p>I've got a problem with <code>EntityFramework</code>. In my app there is an async <code>GetCollections</code> method, which will return a `Task>: </p>
  
  <pre><code>public async Task&lt;List&lt;MyCollection&gt;&gt; GetCollections() {,
  
   IQueryable&lt;MyCollection&gt; query;
   query = ...;
   var result = await query.ToListAsync();
   return result;
  }
  </code></pre>
  
  <p>Problem is the <code>ToListAsync()</code> call, which creates (it looks like) a copy of the entities. When I later modify some of the returned collections and call <code>DbContext.SaveChanges()</code> an exception is thrown, because multiple entities with same primary key are to store. So my question is, what can i do about it?</p>
  
  <p>Edit:</p>
  
  <p>Okay I have rewritten this method to return an <code>IQueriable</code> instead. This fixes the problem with multiple entities with same primary key, but when looping through the IQueriable and modifying entities, an exception is thrown because a second connection to the Database cannot be instantiated. Is there any other type I can return, which fixes this problem?</p>