• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
Show / Hide Table of Contents

Method WriteToDataSource

WriteToDataSource(WriteOperation)

Responsible for atomic write operations on the data source.

Declaration
OperationResult WriteToDataSource(WriteOperation operation)
Parameters
Type Name Description
WriteOperation operation

Write operation applied on the data source.

Returns
Type Description
OperationResult

Failed operations, null otherwise.

Examples

The following example performs a single operation on data source.

public OperationResult WriteToDataSource(WriteOperation operation)
{
    bool result = false;
    OperationResult operationResult = new OperationResult(operation, OperationResult.Status.Failure);
    object value = operation.ProviderItem.GetValue<object>();

    if (value.GetType().Equals(typeof(Customer)))
    {
        result = _source.SaveCustomer((Customer)value);
    }
    if (result) operationResult.OperationStatus = OperationResult.Status.Success;
    return operationResult;
}

WriteToDataSource(ICollection<WriteOperation>)

Responsible for bulk write operations on the data source.

Declaration
ICollection<OperationResult> WriteToDataSource(ICollection<WriteOperation> operations)
Parameters
Type Name Description
System.Collections.Generic.ICollection<WriteOperation> operations

Array of write operations applied on the data source.

Returns
Type Description
System.Collections.Generic.ICollection<OperationResult>

Array of failed operations.

Examples

The following example performs multiple operations on the data source.

public ICollection<OperationResult> WriteToDataSource(ICollection<WriteOperation> operations)
{
    ICollection<OperationResult> operationResults = new OperationResult[operations.Count];

    foreach(WriteOperation operation in operations)
    {
        operationResults.Add(WriteToDataSource(operation));
    }

    return operationResults;
}

WriteToDataSource(ICollection<DataTypeWriteOperation>)

When datatype is created or removed as bulk, data source will be notified with this method.

Declaration
ICollection<OperationResult> WriteToDataSource(ICollection<DataTypeWriteOperation> dataTypeWriteOperations)
Parameters
Type Name Description
System.Collections.Generic.ICollection<DataTypeWriteOperation> dataTypeWriteOperations

Operation containing properties.

Returns
Type Description
System.Collections.Generic.ICollection<OperationResult>

OperationResult.

Examples
public ICollection<OperationResult> WriteToDataSource(ICollection<DataTypeWriteOperation> operations)
{
    List<OperationResult> operationResult = new List<OperationResult>();

    foreach (DataTypeWriteOperation operation in operations)
    {
        var list = new List<Product>();
        ProviderDataTypeItem<object> cacheItem = operation.ProviderItem;
        Product product = (Product)cacheItem.Data;

        switch (operation.OperationType)
        {
            case DatastructureOperationType.CreateDataType:
                // Insert logic for creating a new List
                IList myList = new List<Product>();
                myList.Add(product.Id);
                break;

            case DatastructureOperationType.AddToDataType:
                // Insert logic for any Add operation 
                list.Add(product);
                break;

            case DatastructureOperationType.DeleteFromDataType:
                // Insert logic for any Remove operation
                list.Remove(product);
                break;

            case DatastructureOperationType.UpdateDataType:
                // Insert logic for any Update operation 
                list.Insert(0, product);
                break;
        }

        // Write Thru operation status can be set according to the result. 
        operationResult.Add(new OperationResult(operation, OperationResult.Status.Success));
    }

    return operationResult;
}
In This Article
  • WriteToDataSource(WriteOperation)
  • WriteToDataSource(ICollection<WriteOperation>)
  • WriteToDataSource(ICollection<DataTypeWriteOperation>)

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
� Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top