title: LINQ to SQL (DBML) update entity from different data context
body: <p>I'm trying to update Entity/model using LINQ to SQL (DBML). but I'm not able to do it.</p>
  
  <p>Here is my code snippet.</p>
  
  <pre><code>public void Update(Customer customer)
  {
      using (MyDataContext db = new MyDataContext())
      {
          db.Customers.Attach(customer, true);
          db.SubmitChanges();
      }
  }
  
  public Customer GetByID(int ID)
  {
      using (MyDataContext db = new MyDataContext())
      {
          return db.Customers.FirstOrDefault(c =&gt; c.CustomerID == ID);
      }
  }
  </code></pre>
  
  <p>My scenario is: I get the customer object and bind the customer object to form. and after change the form input data. Data is perfectly change but when I call update method. It's not updating it and I have this error:</p>
  
  <blockquote>
    <p>An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.</p>
  </blockquote>
  
  <p>I searched a lots of internet but I'm not able to find any appropriate solution. I also modified my update function like that:</p>
  
  <pre><code>public void Update(Customer customer)
  {
      using (MyDataContext db = new MyDataContext())
      {
          var originalCustomer = db.Customers.FirstOrDefault(c =&gt; c.CustomerID == customer.CustomerID);
          db.Customers.Attach(customer, originalCustomer);
          db.SubmitChanges();
      }
  }
  </code></pre>
  
  <p>But still getting the same error.</p>
  
  <p><em>I don't want to get Customer from database and update it properties from parameter customer properties. I want to use the same parameter customer and update it in database.</em></p>
  
  <p>Please help me.
  Thanks!</p>