problem inserting data through Entity framework's Addto() method.

  • Thread starter Thread starter Prasad
  • Start date Start date
P

Prasad

Hi,
I am trying to insert data into coordinators table which is linked
with Customer table through cid.
I have following code for insertion:

public void InsertCoordinator(Coordinator coordinator)

{

int CustomerID = Convert.ToInt32(SessionManager.GetSessionManager
().CustomerKey);

Customer customer = new Customer { cid = CustomerID };

this.Context.AttachTo("Customers",customer);

coordinator.customer = customer;

this.Context.AddToCoordinators(coordinator);

this.Context.SaveChanges();

}

However it gives me following error during insertion:
[System.InvalidOperationException] = {"The object cannot be added to
the object context. The object�s EntityKey has an ObjectStateEntry
that indicates that the object is already participating in a different
relationship."}

Can you please suggest what may be the issue. How can i resolve this
error.

Thanks.
 
Back
Top