This question is locked. New answers and comments are not allowed.
I'm having a problem with entries in a join table being deleted. Here is the situation:
I'm operating in an n-tier environment, so there is a service layer (.NET Web API) that pulls objects out of the database and serializes (JSON) them back to a client. The client then makes any changes it needs and serializes them back to the service layer which just attaches the object and calls SaveChanges. When the service layer is serializing data, it creates a detached copy of only the pieces of the object it needs.
So, let's say that I have 3 object types: Users, Emails, and Claims. Emails has a foreign key back to Users, so it's just a one-to-many relationship. Users and Claims are joined together in a many-to-many relationship using a join table (UserClaims). When the User object is serialized back and forth, the Emails and Claims are not included (they were never detached), so they are just serialized as empty lists ("[]"). When the User object is reattached in the service layer and SaveChanges is called, the Emails are left alone, even though they weren't present in the User object before reattaching, but the Claims objects are deleted from the join table. It seems to me like these should be working the same, but they're not. I also don't know if there's a way to look up whether there are any pending changes on the UserClaims table since it's not a real type in OpenAccess that can be passed to context.GetChanges().GetDeletes<>(), just a hidden join table. The only way I know that this is where they are getting deleted is by tracking the SQL that is being generated.
Is there anything that I can do to convince OpenAccess to leave the Claims alone without having to always serialize the Claims with the User objects?
I'm operating in an n-tier environment, so there is a service layer (.NET Web API) that pulls objects out of the database and serializes (JSON) them back to a client. The client then makes any changes it needs and serializes them back to the service layer which just attaches the object and calls SaveChanges. When the service layer is serializing data, it creates a detached copy of only the pieces of the object it needs.
So, let's say that I have 3 object types: Users, Emails, and Claims. Emails has a foreign key back to Users, so it's just a one-to-many relationship. Users and Claims are joined together in a many-to-many relationship using a join table (UserClaims). When the User object is serialized back and forth, the Emails and Claims are not included (they were never detached), so they are just serialized as empty lists ("[]"). When the User object is reattached in the service layer and SaveChanges is called, the Emails are left alone, even though they weren't present in the User object before reattaching, but the Claims objects are deleted from the join table. It seems to me like these should be working the same, but they're not. I also don't know if there's a way to look up whether there are any pending changes on the UserClaims table since it's not a real type in OpenAccess that can be passed to context.GetChanges().GetDeletes<>(), just a hidden join table. The only way I know that this is where they are getting deleted is by tracking the SQL that is being generated.
Is there anything that I can do to convince OpenAccess to leave the Claims alone without having to always serialize the Claims with the User objects?