EntityGraph ExtractState fails with Composition attribute

Oct 25, 2011 at 10:35 PM

Hi,

Found a bug in EntityGraph:

I have a parent-child entity relation and use "Composition" attribute. When the child entity get some change, the parent entity gets the "HasChange" attribute (as expected).

Then if you try to use the entity.ExtractState(RiaServicesContrib.ExtractType.OriginalState) you get a null reference exception.

I downloaded the source code of EntityGraph and debug, and find the following in the ExtractState method:

            if (extractType == ExtractType.OriginalState && entity.HasChanges)

                extractEntity = entity.GetOriginal();

            else

                extractEntity = entity;

so as "HasChanges" is true for the parent it's processed the "true" branch and extractEntity gets "null" from GetOriginal(). Couple of lines down the code throws an exception.

 

Hope this help.

 

Regards

Developer
Oct 29, 2011 at 7:03 PM

Hi,

Thanks for trying EntityGraph.

The short answer is, EntityGraph doesn't support the "Composition" attribute.

The somewhat longer answer is, if you could provide code for a minimal example demonstrating the issue, I'll have a look at it to see if we can easily fix this issue.

Kinds regards,

Merijn

Oct 30, 2011 at 10:33 PM

Hi Merijn,

First of all thanks for the answers. I already worked arround this issue in my code.

As explained in my post, the issue (as far as I understand) is in your ExtractState method. I think this could be solved checking in the true branch if extractEntity is null (this happens when in composition you modify a child entity and the parent entity gets the HasChanged but actually doesn't have any one, so GetOriginal returns null) and in that case assigning "entity" to "extractEntity".

Regards.

Adrián