Skip to content

Support commands

Jon Smith edited this page Jan 14, 2015 · 1 revision

There are a couple of support methods in GenericServices that you may found useful too. They are:

SaveChangesWithChecking (sync and async)

GenericServices uses the method SaveChangesWithChecking() / SaveChangesWithCheckingAsync() to commit any changes to the database. It returns an ISuccessOrErrors status saying whether the save was successful.

This method catches Validation Errors and some SQL Errors (see Dictionary for catching SQL errors) and returns Errors in the status rather than throwing an exception. You may find this useful elsewhere in your application.

The signature of the methods are:

  • ISuccessOrErrors SaveChangesWithChecking()
  • Task<ISuccessOrErrors> SaveChangesWithCheckingAsync()

RealiseSingleWithErrorChecking (sync and async)

This is used when you expect to get one result for a query. It returns a status and, if the status .IsValid() property is true, the single class found by the query. It also optionally called the configuration set property RealiseSingleWithChecking(exception, callingMethodName) if there is an exception. This allows the developed to check the exception and return an error if appropriate. Use this when it is preferable to get error messages rather than an exception.

The method is an extension method, so it can chained onto the end of a LINQ query. The signature of the methods are:

  • ISuccessOrErrors<T> RealiseSingleWithErrorChecking<T>(this IQueryable<T> request)
  • Task<ISuccessOrErrors<T>> RealiseSingleWithErrorCheckingAsync<T>(this IQueryable<T> request)