Troubleshooting Self-Monitoring

I use self-examination in a WCF client-server application. My WCF service returns various entities and can be updated using the appropriate update methods.

It worked fine, but now I have problems. To maintain focus, I limit this discussion to a specific case, simplified to the necessary subjects.

One of my tables is called SystemDefinition. It does not have foreign keys, but one other table (Route) has a foreign key. Therefore, it has one navigation property in the entity model (called routes). All other columns are scalars. The table and corresponding entities have a primary key column named Id, of type Guid. The database is SQL Server Compact v3.5.

To reproduce the problem, I can:

  • Get a single SystemDefinition using the WCS service's GetSystem () method
  • In the client, call MarkAsDeleted () on the entity
  • Call UpdateSystem (), passing the object as a parameter

The code in UpdateSystem () is simple (unnecessary code for clarity):

_objectContext.SystemDefinitions.ApplyChanges(system);
_objectContext.SaveChanges();

The object is retrieved without the Include () clause, which means that the Routes collection is empty (and in any case, an error still occurs if Route with foreign keys does not have system names). So the SystemDefinition object that I pass to the Update method is the only object in the graph . However, I still get the following exception:

InvalidOperationException: AcceptChanges , ObjectStateManager. , AcceptChanges.

(ApplyChanges). , ObjectContext , , .

, ( ObjectContext.FixupKey()), , Microsoft , , .

, ? . ?

PS. , , GetHashCode() Equals() . , , ObjectStateManager , - . ( ), , , . . .

+3
1

, _objectContext , . , ( ) , ​​ .

: , .

, , .

+1

Source: https://habr.com/ru/post/1768419/


All Articles