A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.umbraco.com/umbraco-commerce/key-concepts/readonly-and-writable-entities below:

ReadOnly and Writable Entities | Umbraco Commerce

ReadOnly and Writable Entities | Umbraco Commerce
  1. Key Concepts
ReadOnly and Writable Entities

Great performance and simplified change tracking using ReadOnly and Writable entities in Umbraco Commerce.

When working with the Umbraco Commerce entities, it's important to know that all entities come in two states, ReadOnly and Writable. By default, all Umbraco Commerce API methods will return entities in their ReadOnly state. This means that when you are accessing Umbraco Commerce entities directly from an API endpoint you are able to read and iterate over its properties. You won't, however, be able to make changes to that entity without first converting it into its Writable state.

Why have ReadOnly and Writable entities?

The reason why we have split entities in this way for a number of reasons, however, the two primary factors are:

Converting a ReadOnly entity into a Writable entity

To convert a ReadOnly entity to its Writable form, call the entity's AsWritableAsync(uow) method. Pass in a valid Unit of Work instance associated with this operation. Once a Writable entity is available, perform the desired write operations and persist the changes back to the database.

await _uowProvider.ExecuteAsync(async (uow) =>
{
    // Fetch the currency
    var currency = await _currencyService.GetCurrencyAsync(currencyId);

    // Convert the currency into it's Writable form
    var writableCurrency = await currency.AsWritableAsync(uow);

    // Peform our write operation
    await writableCurrency.SetNameAsync("New Name");

    // Persist the changes to the database
    await _currencyService.SaveCurrencyAsync(currency);

    // Close our transaction
    uow.Complete();
});

All write operations must occur within a Unit of Work so by passing in a Unit of Work instance into the entities AsWritableAsync method, we are ensuring that you are in fact within an active Unit of Work.

Last updated 4 months ago


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4