using System.Linq.Expressions; namespace DigitalData.Core.Abstraction.Application.Repository; /// /// Provides methods for executing common queries on a given entity type. /// This interface abstracts away the direct usage of ORM libraries (such as Entity Framework) for querying data /// and provides asynchronous and synchronous operations for querying a collection or single entity. /// /// The type of the entity being queried. public interface IReadQuery { /// /// Adds a filter to the query using the specified predicate expression. /// This method allows chaining multiple filter conditions to refine the query results. /// /// An expression that defines the filter condition for the entity. /// The current instance with the applied filter. public IReadQuery Where(Expression> expression); /// /// Asynchronously retrieves the first entity or a default value if no entity is found. /// /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. The task result contains the entity or a default value. public Task FirstOrDefaultAsync(CancellationToken cancellation = default); /// /// Asynchronously retrieves a single entity or a default value if no entity is found. /// /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. The task result contains the entity or a default value. public Task SingleOrDefaultAsync(CancellationToken cancellation = default); /// /// Asynchronously retrieves a list of entities. /// /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. The task result contains the list of entities. public Task> ToListAsync(CancellationToken cancellation = default); /// /// Asynchronously retrieves the first entity. Throws an exception if no entity is found. /// /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. The task result contains the first entity. public Task FirstAsync(CancellationToken cancellation = default); /// /// Asynchronously retrieves a single entity. Throws an exception if no entity is found. /// /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. The task result contains the single entity. public Task SingleAsync(CancellationToken cancellation = default); /// /// Synchronously retrieves the first entity or a default value if no entity is found. /// /// The first entity or a default value. public TEntity? FirstOrDefault(); /// /// Synchronously retrieves a single entity or a default value if no entity is found. /// /// The single entity or a default value. public TEntity? SingleOrDefault(); /// /// Synchronously retrieves a list of entities. /// /// The list of entities. public IEnumerable ToList(); /// /// Synchronously retrieves the first entity. Throws an exception if no entity is found. /// /// The first entity. public TEntity First(); /// /// Synchronously retrieves a single entity. Throws an exception if no entity is found. /// /// The single entity. public TEntity Single(); }