title: How to avoid spinning up multiple contexts in entity framework
body: <p>In Entity framework, trying to run the following code:</p>
  
  <pre><code>        using (MyEntities ctx = new myEntities())
          {
              Entity.Customers.Build buildId = new ctx.Build();
              buildId.CustomerService = customerService;
              buildId.datCreatedDate = DateTime.Now;
              buildId.strBuildSchema = schema;
              buildId.Status = "Success";
              ctx.AddToBuilds(buildId);
              ctx.SaveChanges();
          }
  </code></pre>
  
  <p>Results in the error "An entity object cannot be referenced by multiple instances of IEntityChangeTracker". </p>
  
  <p>As far as I can tell, the problem is that the Build object I'm creating comes from a new instance of the Entity Framework context which is distinct from the context that does the AddToBuilds() statement.</p>
  
  <p>However I can't work out how to get past this problem. I can't seem to create a new Build direct from an instantiation of the Entity context object i.e. ctx in the code above? Is there a way to do this, or am I missing another obvious workaround?</p>
  
  <p>Cheers,
  Matt</p>