title: Updating one entity with one context, and inserting a new with another context?
body: <p>Greetings and thanks for reading my post.. : </p>
  
  <p>I am updating an entry (Photo) within a using </p>
  
  <pre><code>using (context = new PhotoEntities())
  {
      // ...
  
      context.Entry(photo).State = EntityState.Modified;
  }
  </code></pre>
  
  <p>The problem is that when i save this entry using </p>
  
  <pre><code>success = context.SaveChanges() &gt; 0;
  if (success)
  {
       FeedServices.CreatePhotoFeed(photo);
  }
  </code></pre>
  
  <p>I still need to have the context since i'm inserting a new feed. So.. i have tried using a different context and i'm experiencing an error that says : </p>
  
  <pre><code>An error occurred while updating the entries. 
  See the inner exception for details.",
  "ExceptionType":"System.Data.Entity.Infrastructure.DbUpdateException",
  "StackTrace":"   at System.Data.Entity.Internal.InternalContext.SaveChanges()\r\n  
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()\r\n   
  at System.Data.Entity.DbContext.SaveChanges()\r\n   
  at ServiceLibrary.Services.FeedServices.CreatePhotoFeed(Photo photo) 
  in c:\\PhotoApp\\ServiceLibrary
  </code></pre>
  
  <p>Here is the code that fails: </p>
  
  <pre><code>public static void CreatePhotoFeed(Photo photo)
  {
      using (var pcontext = new PhotoEntities())
      {
          // TODO : Guest access handling.,...
          var sourceUser = UserServices.GetLoggedInUser();
  
          Feed feed = new Feed();
          feed.UserId = sourceUser.Id;
          feed.PhotoId = photo.Id;
          feed.SourceUsername = sourceUser.Firstname + " " + sourceUser.Lastname;
          feed.TargetUsername = photo.User.Firstname + " " + photo.User.Lastname;
          feed.DateCreated = DateTime.UtcNow;
          feed.Feedtext = "lastet opp et nytt foto";
          feed.FeedType = FeedTypeEnum.FeedType.NewPhoto.ToString();
  
          pcontext.Feeds.Add(feed);
  
          // this throws the error
          pcontext.SaveChanges();
      }
  }
  </code></pre>