I am inserting some objects into the database, but getting the following errors:
An exception of type 'System.InvalidOperationException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
I have tried to research and find the issue, but couldn't find proper way of resolving and understanding the issue. Any help is appreciated.
Here is small source part that causes the error:
SysUsers User = GetUser()
foreach (int country in data.countries) {
foreach (int street in data.streets)
{
BrowsedData tempBrowsed = new BrowsedData();
MapInfo tempInformation = WorldInformationController.FindInformation(country, street);
tempBrowsed.Information = tempInformation;
tempBrowsed.User = User;
tempBrowsed.UpdatedBy = User;
tempBrowsed.sDateTime = data.IndividualFiscalYearEnds
.Where(a => a.C_ID == country)
.Select(a => a.LastDate).FirstOrDefault();
this.Database.BrowsedData.Add(tempBrowsed);
this.Database.SaveChanges();
}
}
The error denotes to this line: this.Database.BrowsedData.Add(tempBrowsed);