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
I'm having a problem after migrating my RC1 Web Application to RC2. I'll try to describe my problem as best as possible.The code did work perfectly in RC1. I'm using SQLite as provider by the way.
First I got a class A which has a virtual property of type B
public class A {
public virtual B ObjectB { get; set;}
}
And class B has a property Id as follows
public class B {
public int Id { get; set;}
}
So my problem appers when I try to set the property ObjectB of an Object of Type A, to an existing object B fetched from the database. Perhaps this code snippet explains it better:
A a = new A();
a.ObjectB = b //b has been fetched from the database
db.A.Add(a); //Here the exception happens
If I try to add the new a to the database I get an DbUpdateException: {"SQLite Error 19: 'UNIQUE constraint failed: B.Id"}. This happens because the b is incorrectly labeled as Added by the ChangeTracker. But the b already exists in the Database. If I change the state to Unchanged manually the exception disappers and all runs well.
I hope my explantion was good enough. Let me know if i did anything wrong.
The text was updated successfully, but these errors were encountered:
mb236
changed the title
Entities incorrectly labeled as Added in ChangeTracker
Entities incorrectly labeled as Added by the ChangeTracker
May 20, 2016
I'm having a problem after migrating my RC1 Web Application to RC2. I'll try to describe my problem as best as possible.The code did work perfectly in RC1. I'm using SQLite as provider by the way.
First I got a class A which has a virtual property of type B
And class B has a property Id as follows
So my problem appers when I try to set the property ObjectB of an Object of Type A, to an existing object B fetched from the database. Perhaps this code snippet explains it better:
If I try to add the new a to the database I get an DbUpdateException: {"SQLite Error 19: 'UNIQUE constraint failed: B.Id"}. This happens because the b is incorrectly labeled as Added by the ChangeTracker. But the b already exists in the Database. If I change the state to Unchanged manually the exception disappers and all runs well.
I hope my explantion was good enough. Let me know if i did anything wrong.
The text was updated successfully, but these errors were encountered: