-
Notifications
You must be signed in to change notification settings - Fork 13
GetById Operations
Furkan Güngör edited this page Dec 3, 2021
·
1 revision
With EasyRepository
, your GetById
queries can be run. However, the id value must be the primary key
.
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<Author> GetByIdAsync(Guid id)
{
var entity = await repository.GetByIdAsync<Author>(asNoTracking:true, id);
return entity;
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<object> GetByIdWithSelectAsync(Guid id)
{
return await repository.GetByIdAsync<Author,object>(true, id, projectExpression: select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
});
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<object> GetByIdWithIncludeAsync(Guid id)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
return await repository.GetByIdAsync<Author>(asNoTracking: true, id, includeExpression: include);
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<object> GetByIdWithIncludeAndSelectAsync(Guid id)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
return await repository.GetByIdAsync<Author, object>(asNoTracking: true, id, projectExpression: select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
},includeExpression: include);
}
}
Welcome to the EasyRepository.EFCore
wiki!
Topics:
-
Getting Started
-
Implementations
-
Specification
-
Ardalis.Specification & EasyRepository.EFCore