Make LoadOperation return entities AND ALSO an error message RRS feed

  • Question

  • Is is possible to do this?

    What I'm looking for is a way to send a message back to the client, but NOT throw an exception from the GetEntity(..) DomaiNService method, so that the entity returns, but loadOp.Error has a value. I also don't want to muddy up the model with a generic property I add onto the entity.

    I imagine making this 'work' would require some hacky coding -- and perhaps not even possible because it's wrapped up in the DomainService base class, but I figured I'd ask nonetheless ...

    Wednesday, August 17, 2011 2:07 PM

All replies

  • Hi Joe,

    I do this like this code:

                TreeItemSource = null;
                IsLoading = true;
                if (Context.EntityContainer != null) Context.EntityContainer.GetEntitySet<HierarchyDataService>().Clear();
                LoadOperation<HierarchyDataService> loadOp = Context.Load(Context.GetPersonCategoryHierarchyQuery());
                loadOp.Completed += (sender, arg) =>
                    if (loadOp.HasError)
                        ViewMessage = "There is an error while loading hierarchy";
                        TreeItemSource = CoReTreeViewItem.Source(loadOp.Entities);
                    IsLoading = false;


    Wednesday, August 17, 2011 5:33 PM
  • Hi jsiahann, thanks for your reply.

    I do currently have code like this, but what I'm looking for is a way to pass a message back to the client in addition to the result of the load operation. Being able to stuff this message into the .Error property would seem to be a sloppy/hacky way to do this, and it would break the metaphor you mention. That is, if there is an error, there is no result.

    It would probably help if I explain the scenario.

    In the application we have entities stored in our database that are representations of data stored in external systems, with some extra specialized columns for this application. When a user requests one of these entities, we also check the external source to see if there are updates. Depending on the current state of the external entity, and due to other volatility outside our control, sometimes these updates won't occur or a result won't come back from the external source.

    But when this happens we need to let the user know, and we also need to return the entity shell from OUR database. - Hence the need to break the above metaphor.

    Thursday, August 18, 2011 9:46 AM
  • Hi,

    but what I'm looking for is a way to pass a message back to the client in addition to the result of the load operation.

    Base on your description ,from my experience you can add an extra string property to the entity class ,then pass a message to client side by setting a value to this extra string property in domain service. In this way ,you can get the message in DomainContext.Completed event by retrieving the value of the extra string property in client side.

    Here is a similar thread which provides some solutions for the same issue ,please check it and see whether it helps.


    Hope it can help you.

    Sunday, August 21, 2011 11:38 PM