This little extension method is something I wrote to help cleanup domain context code… just thought I would share:


public static class DomainContextExtensions
{
  public static void Load(this DomainContext domainContext,
                          EntityQuery query,
                          Action<LoadOperation> preprocessCallback,
                          Action<LoadOperation> successCallback,
                          Action<LoadOperation> errorCallback,
                          Action<LoadOperation> postprocessCallback = null)
    where TEntity : Entity
  {
    domainContext.Load(query, load =>
    {
      if (preprocessCallback != null)
        preprocessCallback(load);

      if (load.HasError)
      {
        if (errorCallback != null)
        {
          errorCallback(load);
          load.MarkErrorAsHandled();
        }
      }
      else
      {
        successCallback(load);
      }

      if (postprocessCallback != null)
        postprocessCallback(load);
    }, null);
  }
}

Enjoy!

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...