OpenRIAServices / OpenRiaServices

The Open RIA Services project continues what was previously known as WCF RIA Services.
https://openriaservices.gitbook.io/openriaservices/
Apache License 2.0
54 stars 48 forks source link

Add support for async/await #81

Closed Daniel-Svensson closed 6 years ago

Daniel-Svensson commented 6 years ago

Thank you for Open RIA Services 4.4.

I would like to request the ability to support async/await calls on the domain context.

For example, MyDomainContext context = new MyDomainContext(); context.People.Add(new Person { FirstName = "Colin", LastName = "Blair"

}); await context.SubmitChangesAsync();

Thank you.

This work item was migrated from CodePlex

CodePlex work item ID: '81' Vote count: '1'

Daniel-Svensson commented 6 years ago

[icnocop@2015-09-12] Thank you for the quick response.

I'm using Visual Studio 2013 Update 3 Client: Silverlight 5 nuget package OpenRiaServices.Signed.Silverlight.Core.4.4.0.0

Server: .NET 4.5 nuget packages OpenRiaServices.Signed.EntityFramework.4.4.0.1, OpenRiaServices.Signed.Server.4.4.0.1

Compilation error: The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.

I get the same error even after adding a reference to the nuget package Microsoft.Bcl.Async 1.0.168.

Any ideas?

Thank you.

Daniel-Svensson commented 6 years ago

[danneesset@2015-09-12] Using await with open ria services is fully supported since 4.4.0 so using the code in your example should work fine.

In order to use async/await in Silverlight and other "older" platforms requires you to add a reference to Microsoft's async package https://www.nuget.org/packages/Microsoft.Bcl.Async

** Closed by danneesset 09/12/2015 4:58AM

Daniel-Svensson commented 6 years ago

[danneesset@2015-09-15] You can only use the await keyword in "async" methods.

I recommend that you search for an introduction to async/await. I remember that they had some good at the MSDN magazine, but I could not find it easily from the phone.

I will close this issue since this is a general c# question and not an open RIA issue

Daniel-Svensson commented 6 years ago

[icnocop@2015-09-15] I'm requesting that Open RIA Services be updated so that its methods use the "async" modifier.

In this way, using "await" operator can be supported.

For example, in \OpenRiaServices.DomainServices.Client\Framework\Silverlight\Data\DomainContext.cs:

public virtual async Task<SubmitResult> SubmitChangesAsync(CancellationToken cancellationToken)
{
...
}

Notice the new "async" modifier in the method.

And then I can call it like this:

MyDomainContext context = new MyDomainContext();
context.People.Add(new Person
{
    FirstName = "Daniel",
    LastName = "Svensson"
});
await context.SubmitChangesAsync(null);

Thank you.

Daniel-Svensson commented 6 years ago

[danneesset@2015-09-15]

** Closed by danneesset 09/15/2015 9:31AM

Daniel-Svensson commented 6 years ago

[ColinBlair@2015-09-15] I am sorry, but that is now what the async keyword means. If a method is using the await keyword, then it must be marked as async. If a method is not using await then it should not be marked async. Either way, this is an internal implementation detail that is not and should not be of interest to calling code.

What lets you do an await is that SubmitChangesAsync returns a Task.

Daniel-Svensson commented 6 years ago

[icnocop@2015-09-21] Can you point me to an example of using await on SubmitChangesAsync?

Thank you.