Search documentationEsc

Item types

Pick the right base class — Item, EtagItem, TimeStampedItem, TimeToLiveItem, or FullItem.

The library provides a small family of base classes that opt your model into specific Cosmos DB features. Inherit from the one that has just enough behavior for your scenario.

Hierarchy at a glance

Base classUse when you want…
ItemThe simplest CRUD model. Adds Id, Type, and partition-key handling.
EtagItemItem + an Etag for optimistic concurrency control. Abstract.
TimeStampedItemItem + CreatedTimeUtc, LastUpdatedTimeUtc, and LastUpdatedTimeRaw.
TimeToLiveItemItem + a TimeToLive property that overrides the container default TTL.
FullItemEverything in EtagItem, TimeStampedItem, and TimeToLiveItem.

The corresponding interfaces (IItem, IItemWithEtag, IItemWithTimeStamps, IItemWithTimeToLive) are exposed if you need to compose your own base.

The simplest item

using Microsoft.Azure.CosmosRepository;
public class Product : Item
{
public string Name { get; set; } = null!;
public string CategoryId { get; set; } = null!;
public double Price { get; set; }
public StockInformation Stock { get; set; } = null!;
protected override string GetPartitionKeyValue() => CategoryId;
}

Item already gives you:

  • Id (default: Guid.NewGuid().ToString()).
  • Type (the .NET class name — used as a discriminator inside shared containers).
  • GetPartitionKeyValue() — defaults to Id. Override when partitioning by another field.

When to upgrade