共用方式為


Failures in .NET RIA Services are silent by default

Due to the async nature of the .NET RIA Services programming model, exceptions and errors during load and submits aren't thrown on the client. Instead, the errors are exposed through an Error property which can be found in the event args instances passed in to handlers for the Loaded and Submitted events.

So, the first thing I do whenever I create a new DomainContext instance on the client is add a simple handler for the Loaded event. If I am going to be doing submits, then I add a handler for the Submitted event.

For example,

myDomainContext.Loaded +=

delegate(object sender, LoadedDataEventArgs e)
{
    if (e.Error != null)
{
        throw e.Error;
}
};
myDomainContext.Submitted += delegate(object sender, SubmittedChangesEventArgs e)
{
    if (e.Error != null)
{
        throw e.Error;
}
};

Later on, I might to do more complex things on those event handlers, but at beginning using anonymous methods are just fine.

Comments