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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top