Repository Pattern
Clean abstraction over data access with IRepository, IReadOnlyRepository, and ISearchableRepository interfaces.
Build robust data access layers with Elasticsearch, caching, messaging, and more
// Define your entity
public class Employee : IIdentity, IHaveDates, ISupportSoftDeletes
{
public string Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public DateTime CreatedUtc { get; set; }
public DateTime UpdatedUtc { get; set; }
public bool IsDeleted { get; set; }
}
// Create a repository
public class EmployeeRepository : ElasticRepositoryBase<Employee>, IEmployeeRepository
{
public EmployeeRepository(EmployeeIndex index) : base(index) { }
}
// Use the repository
var employee = await repository.AddAsync(new Employee { Name = "John", Age = 30 });
var found = await repository.FindAsync(q => q.FilterExpression("age:>=25"));