WAQS: Global context

7 reasons to use WAQS

WAQS documentation

 

One of the cool feature of WAQS is the fact that, like with Entity Framework, when you save client context changes, all the SQL operations are executed in the same transaction. With this way if an CUD operation fails, nothing is saved in the DB. So it means that the DB always is in a safe state.

I show you how to use many edmx in my last post.

Sometimes, you want to save changes of many model in the same transaction, particularly if you use many small model instead of a big one as I recommend.

 

WAQS also has a solution for this.

 

When you generate code using GlobalOnly option in the server, WAQS also creates a global service.

 

In the client, you have a special PowerShell command that generates a global client context:

WCFAsyncQueryableServicesGlobalClient[PCL|WPF] ‘"[…]\Contexts.xml"’ ‘"[…]\Global.svc"’

One more time you have intellisense on it. The Contexts.xml is built on each generation with GlobalOnly option.

Note that you have to run it in a project that references all specific client context ones.

 

After executing this command, you can use the IGlobalClientContext interface (that could be injected by Unity in ViewModel constructors).

This interface just have one method SaveChangesAsync that uses an IEnumerable<IClientContext> as parameter.

So you can use it like this:

await globalContext.SaveChangesAsync(new[] { context1, context2, context3 });


With this way all client context SaveChanges are executed in the same transaction.

This entry was posted in 16868. Bookmark the permalink.

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>