I have a project where a dropdownlist
is loaded with the following statements:
var lista = entities.prato.OrderBy(x => x.nome).ToList();
combo.DataTextField = "nome";
combo.DataValueField = "id";
combo.DataSource = lista;
combo.DataBind();
Then I need to retrieve the item from dropdownlist
and use it to create a record, to retrieve the item I use the following line:
ingrediente i = entities.ingrediente.Find (Convert.ToInt32(combo.SelectedItem.Value));
When time saving the record as follows:
ingrediente_prato ip = new ingrediente_prato();
ip.prato = (prato)Session["pratoSelecionado"];
ip.ingrediente = i;
entities.ingrediente_prato.Add(ip);
entities.SaveChanges();
The following error is returned:
An entity object can not be referenced by multiple instances of IEntityChangeTracker
Does anyone have any suggestions?