Skip to main content

Attributes

The library uses attributes to describe the role of entity properties and to configure repositories. All attributes live in the Wemogy.Infrastructure.Database.Core.Attributes namespace.

Entity property attributes

These attributes are applied to properties of an entity class.

AttributeTargetRequiredDescription
[Id]PropertyYesMarks the property that holds the unique identifier of the entity. Must be a string.
[PartitionKey]PropertyYesMarks the property used as the partition key (see Getting Started).
[SoftDeleteFlag]PropertyNoMarks the bool property that flags an entity as soft-deleted (see Soft Delete).
[ETag]PropertyNoOpts the entity into optimistic concurrency (see Optimistic Concurrency).

When you derive from EntityBase, [Id] and [SoftDeleteFlag] are already provided. GlobalEntityBase additionally provides a global [PartitionKey].

Entity using property attributes
using Wemogy.Infrastructure.Database.Core.Abstractions;
using Wemogy.Infrastructure.Database.Core.Attributes;

public class User : EntityBase // provides [Id] Id and [SoftDeleteFlag] IsDeleted
{
[PartitionKey]
public string TenantId { get; set; } = string.Empty;

public string Firstname { get; set; } = string.Empty;
}

Repository attributes

These attributes are applied to the repository interface.

[RepositoryOptions]

Customizes repository behavior.

ParameterTypeDefaultDescription
enableSoftDeleteboolfalseEnables soft delete for the repository.
collectionNamestring?nullOverrides the collection/container name (defaults to the entity name).
IUserRepository.cs
using Wemogy.Infrastructure.Database.Core.Abstractions;
using Wemogy.Infrastructure.Database.Core.Attributes;

[RepositoryOptions(enableSoftDelete: true, collectionName: "users")]
public interface IUserRepository : IDatabaseRepository<User>
{
}

[RepositoryReadFilter]

Registers one or more read filters that are applied to every read operation. Can be specified multiple times.

[RepositoryReadFilter(typeof(GeneralUserReadFilter))]
public interface IUserRepository : IDatabaseRepository<User>
{
}

[RepositoryPropertyFilter]

Registers one or more property filters that are applied to every entity returned by a read operation. Can be specified multiple times.

[RepositoryPropertyFilter(typeof(GeneralUserPropertyFilter))]
public interface IUserRepository : IDatabaseRepository<User>
{
}