Click here to Skip to main content
14,836,361 members
Please Sign up or sign in to vote.
1.70/5 (3 votes)
I have got two tables in database

1) State (stateid,statename)

2) City(cityid, stateid, cityname)

I am using Entity framework for db manipulation

I want to insert data into City table with the reference to State Table using entity framework

For that i wrote the following code

C#
MyModel mdl= new MyModel();
City ct=new City();

ct.cityname="Dallas";
ct.State=mdl.State.Where(u=>u.stateid==1);

mdl.AddToCity(ct);
mdl.SaveChanges();


There are data in "state" table.

But i am getting following error at "mdl.AddToCity(ct)"

"An entity object cannot be referenced by multiple instances of IEntityChangeTracker"
Posted

1 solution

You need to google before posting the question. This is a generic error message. Check the details here

http://www.lmgtfy.com/?q=An+entity+object+cannot+be+referenced+by+multiple+instances+of+IEntityChangeTracker[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900