IDataStoreBase.RetrieveAsync(object[] arguments, CancellationToken cancellationToken) Method
.NET Standard 2.x
Asynchronously retrieves rows from the database.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public Task<int> RetrieveAsync(object[] arguments, CancellationToken cancellationToken)
Pararmeters
arguments
System.Object[]
One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in the DataStore.
NOTE: This parameter is required.
cancellationToken
CancellationToken
A cancellation token that can be used by other objects or threads to receive notice of cancellation.
Returns
Task<int>
Returns a task that represents the asynchronous operation.
Remarks
After rows are retrieved, the DataStore's filter is applied. Therefore, any retrieved rows that do not meet the filter criteria are immediately moved to the filter buffer and are not included in the return count.
Before you can retrieve rows for the DataStore, you must specify a DataContext
object with the constructor of DataStore or SetDataContext
method to establish a database connection.
Normally, when you call the RetrieveAsync
method, any rows that are already in the DataStore are discarded and replaced with the retrieved rows. You can set DwRetrieveEventArgs.IsResetBuffer
to false
in the RetrieveStart
event to prevent this. In this case, RetrieveAsync
adds any retrieved rows to the ones that already exist in the buffers.
Events
The RetrieveAsync
method triggers these events: RetrieveStart
and RetrieveEnd
.
None of these events is triggered if the data source is external, because RetrieveAsync
always fails. You must use one of the import methods to populate the DataStore.
Examples
The following code example retrieves data asynchronously from the database. It uses a CancellationTokenSource
type parameter to make this operation cancelable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DWNet.Data;
namespace Appeon.ApiDoc.IDataStoreBaseExamples
{
public class RetrieveAsyncExample
{
private readonly SchoolContext _context;
public RetrieveAsyncExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public async Task<int> Example2(CancellationTokenSource cts)
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
int result = 0;
try
{
// Retrieves rows from the database for datastore
// If a task has been cancelled, the call to the
// DataStore.RetrieveAsync method throws an OperationCanceledException.
result = await datastore.RetrieveAsync(2, cts.Token);
Console.WriteLine("After Retrieve, Rowcount: {0}",
datastore.RowCount);
}
catch (OperationCanceledException e)
{
// The operation was cancelled before completion.
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
cts.Dispose();
}
return result;
/*This code produces the following output:
A task was canceled.
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x