Class DataStore<T>
Each DataStore in your application represents a collection on your backend. The DataStore class manages the access of data between the Kinvey backend and the app. The DataStore provides simple CRUD operations on data, as well as powerful querying and synchronization APIs.
Inherited Members
Namespace: Kinvey
Assembly: Kinvey.dll
Syntax
public class DataStore<T> : KinveyQueryable<T> where T : class, new()
Type Parameters
Name | Description |
---|---|
T | The type of an entity. |
Properties
| Improve this Doc View SourceAutoPagination
Indicates whether auto pagination is enabled on this datastore, defaulted to false.
Declaration
public bool AutoPagination { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
CollectionName
Represents the name of the collection.
Declaration
public string CollectionName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The name of the collection. |
DeltaSetFetchingEnabled
Indicates whether delta set fetching is enabled on this datastore, defaulted to false.
Declaration
public bool DeltaSetFetchingEnabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
KinveyClient
Gets or sets the Kinvey client that is used for making data requests. Client
Declaration
public AbstractClient KinveyClient { get; set; }
Property Value
Type | Description |
---|---|
AbstractClient | The Kinvey client. |
StoreType
Gets the type of the store. DataStoreType
Declaration
public DataStoreType StoreType { get; }
Property Value
Type | Description |
---|---|
DataStoreType | The type of the store. |
Methods
| Improve this Doc View SourceClearCache(IQueryable<T>)
Removes data from local storage. This does not affect the backend.
Declaration
public KinveyDeleteResponse ClearCache(IQueryable<T> query = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<T> | query | [optional] Query parameter. |
Returns
Type | Description |
---|---|
KinveyDeleteResponse | Details of the clear operation, including the number of entities that were cleared. |
Collection(String, AbstractClient)
Gets an instance of the DataStore<T>.
Declaration
public static DataStore<T> Collection(string collectionName, AbstractClient client = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName | Collection name of the Kinvey collection backing this DataStore |
AbstractClient | client | [optional] Kinvey Client used by this DataStore. If the client is not specified, the SharedClient is used. |
Returns
Type | Description |
---|---|
DataStore<T> | The DataStore instance. |
Collection(String, DataStoreType, AbstractClient)
Gets an instance of the DataStore<T>.
Declaration
public static DataStore<T> Collection(string collectionName, DataStoreType type, AbstractClient client = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName | Collection name of the Kinvey collection backing this DataStore |
DataStoreType | type | The DataStoreType of this DataStore instance |
AbstractClient | client | [optional] Kinvey Client used by this DataStore. If the client is not specified, the SharedClient is used. |
Returns
Type | Description |
---|---|
DataStore<T> | The DataStore instance. |
FindAsync(IQueryable<Object>, KinveyDelegate<List<T>>, CancellationToken)
Perfoms a find operation, with an optional query filter.
Declaration
public Task<List<T>> FindAsync(IQueryable<object> query = null, KinveyDelegate<List<T>> cacheResults = null, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<System.Object> | query | [optional] LINQ-style query that can be used to filter the search results |
KinveyDelegate<List<T>> | cacheResults | [optional] The intermediate cache results, returned via delegate prior to the network results being returned. This is only valid if the DataStoreType is CACHE |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<List<T>> | The async task with the list of entities. |
FindByIDAsync(String, KinveyDelegate<T>, CancellationToken)
Perfoms a find operation, based on a given Kinvey ID.
Declaration
public Task<T> FindByIDAsync(string entityID, KinveyDelegate<T> cacheResult = null, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | entityID | The ID of the entity to be retrieved. |
KinveyDelegate<T> | cacheResult | [optional] The intermediate cache results, returned via delegate prior to the network results being returned. This is only valid if the DataStoreType is CACHE. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<T> | The async task with an entity. |
FindWithMongoQueryAsync(String)
Performs a find operation on the network the with mongo query async.
Declaration
public Task<List<T>> FindWithMongoQueryAsync(string queryString)
Parameters
Type | Name | Description |
---|---|---|
System.String | queryString | Query string in MongoDB syntax. |
Returns
Type | Description |
---|---|
Task<List<T>> | The list of entities that match the query. |
GetCountAsync(IQueryable<Object>, KinveyDelegate<UInt32>, CancellationToken)
Gets a count of all the entities in a collection
Declaration
public Task<uint> GetCountAsync(IQueryable<object> query = null, KinveyDelegate<uint> cacheCount = null, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<System.Object> | query | [optional] LINQ-style query that can be used to filter the search results. |
KinveyDelegate<System.UInt32> | cacheCount | [optional] The intermediate cache results, returned via delegate prior to the network results being returned. This is only valid if the DataStoreType is CACHE |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<System.UInt32> | The async task which returns the count. |
GetCustomRequestProperties()
Gets the custom request properties.
Declaration
public JObject GetCustomRequestProperties()
Returns
Type | Description |
---|---|
JObject | The custom request properties. |
GetSyncCount(Boolean)
Get a count of the number of items currently in the sync queue, either for a particular collection or total count.
Declaration
public int GetSyncCount(bool allCollections = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allCollections | [optional] Flag to determine if count should be for all collections. Default to false. |
Returns
Type | Description |
---|---|
System.Int32 | The sync queue item count. |
GroupAndAggregateAsync(EnumReduceFunction, String, String, IQueryable<Object>, KinveyDelegate<List<GroupAggregationResults>>, CancellationToken)
Gets the aggregate value, by grouping, of the values in the given entity field.
Declaration
public Task<List<GroupAggregationResults>> GroupAndAggregateAsync(EnumReduceFunction reduceFunction, string groupField = "", string aggregateField = "", IQueryable<object> query = null, KinveyDelegate<List<GroupAggregationResults>> cacheDelegate = null, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
EnumReduceFunction | reduceFunction | The value from EnumReduceFunction. |
System.String | groupField | [optional] Property name of field to be used in grouping. |
System.String | aggregateField | [optional] Property name of field to be used in aggregation. This is not necessary when using the REDUCE_FUNCTION_COUNT method. |
IQueryable<System.Object> | query | [optional] Query used to filter results prior to aggregation. |
KinveyDelegate<List<GroupAggregationResults>> | cacheDelegate | [optional] Delegate used to return the sum aggregate value based on what is available in offline cache. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<List<GroupAggregationResults>> | The sum of the values of the given property name for the entities in the DataStore<T>. |
PullAsync(IQueryable<Object>, Int32, Boolean, CancellationToken)
Pulls data from the backend to local storage
This API is not supported on a DataStore of type NETWORK. Calling this method on a network data store will throw an exception.
Declaration
public Task<PullDataStoreResponse<T>> PullAsync(IQueryable<object> query = null, int count = null, bool isInitial = false, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<System.Object> | query | [optional] Query parameter. |
System.Int32 | count | [optional] The needed count of entities. |
System.Boolean | isInitial | [optional] If |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<PullDataStoreResponse<T>> | Entities that were pulled from the backend. |
Purge(IQueryable<T>)
Removes pending write operations from local storage. This prevents changes made on the client from being persisted on the backend.
Declaration
public int Purge(IQueryable<T> query = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<T> | query | [optional] Query parameter. |
Returns
Type | Description |
---|---|
System.Int32 | The number of pending operations that were purged. |
PushAsync(CancellationToken)
Push local data in the datastore to the backend. This API is not supported on a DataStore of type NETWORK. Calling this method on a network data store will throw an exception.
Declaration
public Task<PushDataStoreResponse<T>> PushAsync(CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<PushDataStoreResponse<T>> | PushDataStoreResponse indicating errors, if any. |
RemoveAsync(IQueryable<Object>, CancellationToken)
Deletes a list of entities by the query.
Declaration
public Task<KinveyDeleteResponse> RemoveAsync(IQueryable<object> query, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<System.Object> | query | Expression for deleting entities. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<KinveyDeleteResponse> | KinveyDeleteResponse object. |
RemoveAsync(String, CancellationToken)
Deletes the entity associated with the provided id
Declaration
public Task<KinveyDeleteResponse> RemoveAsync(string entityID, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | entityID | The Kinvey ID of the entity to delete. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<KinveyDeleteResponse> | The async task. |
SaveAsync(T, CancellationToken)
Save the specified entity to a Kinvey collection.
Declaration
public Task<T> SaveAsync(T entity, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
T | entity | the entity to save. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<T> | The async task. |
SaveAsync(IList<T>, CancellationToken)
Saves specified entities to a Kinvey collection.
Declaration
public Task<KinveyMultiInsertResponse<T>> SaveAsync(IList<T> entities, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | entities | Entities to save. |
CancellationToken | ct | [optional] CancellationToken used to cancel a request. |
Returns
Type | Description |
---|---|
Task<KinveyMultiInsertResponse<T>> | An async task with the KinveyMultiInsertResponse<T> result. |
SetCustomRequestProperties(JObject)
Sets the custom request properties.
Declaration
public void SetCustomRequestProperties(JObject customheaders)
Parameters
Type | Name | Description |
---|---|---|
JObject | customheaders | Custom headers. |
SetCustomRequestProperty(String, JObject)
Sets a specific custom request property to a JSON object.
Declaration
public void SetCustomRequestProperty(string key, JObject value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key. |
JObject | value | Value. |
Subscribe(KinveyDataStoreDelegate<T>)
Subscribe the specified callback.
Declaration
public Task<bool> Subscribe(KinveyDataStoreDelegate<T> realtimeHandler)
Parameters
Type | Name | Description |
---|---|---|
KinveyDataStoreDelegate<T> | realtimeHandler | Delegate used to forward realtime messages. |
Returns
Type | Description |
---|---|
Task<System.Boolean> | The async task with the boolean result.If |
SyncAsync(IQueryable<Object>, CancellationToken)
Kicks off a bi-directional synchronization of data between the library and the backend. First, the library calls push to send local changes to the backend. Subsequently, the library calls pull to fetch data in the collection from the backend and stores it on the device. You can provide a query as a parameter to the sync API, to restrict the data that is pulled from the backend. The query does not affect what data gets pushed to the backend.
This API is not supported on a DataStore of type NETWORK. Calling this method on a network data store will throw an exception.
Declaration
public Task<SyncDataStoreResponse<T>> SyncAsync(IQueryable<object> query = null, CancellationToken ct = null)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<System.Object> | query | [optional] A query parameter that controls what gets pulled from the backend during a sync operation. |
CancellationToken | ct | [optional] CancellationToken used to cancel the request. |
Returns
Type | Description |
---|---|
Task<SyncDataStoreResponse<T>> | DataStoreResponse indicating errors, if any. |
Unsubscribe()
Unsubscribe this instance.
Declaration
public Task Unsubscribe()
Returns
Type | Description |
---|---|
Task | The async task. |