Repositories
Configure repositories in Umbraco UI Builder.
Defining a Repository
// Example
public class PersonRepository : Repository<Person, int> {
public PersonRepository(RepositoryContext context)
: base(context)
{ }
protected override int GetIdImpl(Person entity) {
return entity.Id;
}
protected override Person GetImpl(int id) {
...
}
protected override Person SaveImpl(Person entity) {
...
}
protected override void DeleteImpl(int id) {
...
}
protected override IEnumerable<Person> GetAllImpl(Expression<Func<Person, bool>> whereClause, Expression<Func<Person, object>> orderBy, SortDirection orderByDirection) {
...
}
protected override PagedResult<Person> GetPagedImpl(int pageNumber, int pageSize, Expression<Func<Person, bool>> whereClause, Expression<Func<Person, object>> orderBy, SortDirection orderByDirection) {
...
}
protected override long GetCountImpl(Expression<Func<Person, bool>> whereClause) {
...
}
protected override IEnumerable<TJunctionEntity> GetRelationsByParentIdImpl<TJunctionEntity>(int parentId, string relationAlias)
{
...
}
protected override TJunctionEntity SaveRelationImpl<TJunctionEntity>(TJunctionEntity entity)
{
...
}
}Changing the Repository Implementation of a Collection
Using the SetRepositoryType() Method
SetRepositoryType() MethodMethod Syntax
Example
Using the SetRepositoryType(Type repositoryType) Method
SetRepositoryType(Type repositoryType) MethodMethod Syntax
Example
Accessing a Repository in Code
Using the GetRepository<TEntity, TId>() Method
GetRepository<TEntity, TId>() MethodMethod Syntax
Example
Using the GetRepository<TEntity, TId>(string collectionAlias) Method
GetRepository<TEntity, TId>(string collectionAlias) MethodMethod Syntax
Example
Last updated
Was this helpful?