Wednesday, October 31, 2012

SIlverlight 5 RIA composition child entity delete

SIlverlight 5 RIA composition child entity delete

I'm using a custom library which generates the DAL for me similar to Entity Framework but not identically and am having a problem using it imposed by RIA. My problem is that the custom DAL produces an IsPersisted property which essentially identifies if the entity has a corresponding DB record. The key part of the delete code looks like ... if(this.IsPersisted) dataAccessor.Delete(); else throw new NotSupportedException("Delete not supported on unpersisted entities.");

The problem comes in when I use RIA to generate the medium between client and server. I have a parent class with a child composition property like class Parent{ ... [Include,Association("Parent_Child","ParentId","ParentId",IsForeignKey=false), Composition] public List Children{get{return (_children = _children??new List());}} }

In the client code, if I then use parent.Children.Remove(child); the correct entity action is relayed to the server but for the IsPersisted flag gets changed to false when the change set is generated which in turn causes a NotSupportedException.

I've done a lot of digging and exploring. After examining the actual network traffic back to the server I see that the ChangeSet being sent to the server actually contains the flaw. It correctly exposes the original entity and values but then in the Delete segment of the changeset I can see the same entity (verified by the same identity) specified again as OriginalEntity but this time all the values are empty except the ID.

If I trace the deserialization of the ChangeSet, I can see it actually create two separate instances of Child, first populated correctly, then again zeroed out. The ChangeSet then only holds the zeroed out version of the child.

Any ideas as to how to fix what RIA is sending up the wire?

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog