سؤال

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<Child> Children{get{return (_children = _children??new List<Child>());}}
}

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?

هل كانت مفيدة؟

المحلول

This specific issue I managed to resolve by applying [RoundtripOriginal] to the IsPersisted property.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top