You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the normal SaveChanges (The second one) call I get the following exception:
System.InvalidOperationException: The instance of entity type 'TranslationEntity' cannot be tracked because another instance with the key value '{Id: 5652fb85-6fbc-40fd-4914-08dd152b7ad7}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
This probably means that it tries to track this entity again somehow. Is it possible to combine both methods in sequence?
The text was updated successfully, but these errors were encountered:
I ran into this and spent so much time looking for a solution. The only solution I found for this problem is to attach the entitie after calling BulkSaveChanges() to let EF know the entity already exist in the database, like so:
var translation = new TranslationEntity();
dbContext.Translations.Add(translation);
dbContext.BulkSaveChanges();
dbContext.Translations.Attach(translation)
dbContext.SaveChanges();
What version of lib are you using, and it this for SqlServer?
Can you make a test to reproduce the issue.
I have added the following one and it passed:
[Theory]
[InlineData(SqlType.SqlServer)]
public void SaveChanges2TimesTest(SqlType dbServer)
{
ContextUtil.DatabaseType = sqlType;
using var context = new TestContext(ContextUtil.GetOptions());
context.Departments.Add(new Department { Id = Guid.NewGuid(), Name = "D1" });
context.BulkSaveChanges();
context.Customers.Add(new Customer { Name = "Ca" });
context.SaveChanges();
}
I'm using the following code:
On the normal SaveChanges (The second one) call I get the following exception:
System.InvalidOperationException: The instance of entity type 'TranslationEntity' cannot be tracked because another instance with the key value '{Id: 5652fb85-6fbc-40fd-4914-08dd152b7ad7}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
This probably means that it tries to track this entity again somehow. Is it possible to combine both methods in sequence?
The text was updated successfully, but these errors were encountered: