[EFCore] AbpODataEntityController SingleResult performs full table scan, alternatives?
See original GitHub issue- Abp 3.9.0
- .Net Core 2.1
- EF Core
As the title suggests, this seems to be by design, since the AbpODataEntityController implements the Get for a single entity (e.g. http://localhost:21021/odata/Persons(11)) by calling GetAll()
and then performing a Where
such as :
[EnableQuery]
public virtual SingleResult<TEntity> Get([FromODataUri] TPrimaryKey key)
{
var entity = Repository.GetAll().Where(e => e.Id.Equals(key));
return SingleResult.Create(entity);
}
However in EfCoreRepositoryBaseOfTEntityAndTPrimaryKeys GetAll
() calls GetAllIncluding
() which is implemented like this:
public override IQueryable<TEntity> GetAllIncluding(params Expression<Func<TEntity, object>>[] propertySelectors)
{
var query = Table.AsQueryable();
...
return query;
}
Table.AsQueryable()
results in a full table scan whereas the desired result is a single entity.
I’m aware that we can just override the SingleResult
function in our controller in the Web.Core to query single rows for example:
[EnableQuery]
public override SingleResult<Person> Get([FromODataUri] int key)
{
var entity = new List<Person> { _repository.Single(c => c.Pin == key) }.AsQueryable();
return SingleResult.Create(entity);
}
However this will not include the navigation properties (e.g. Addresses) unless we explicitly reference the EFCore nuget package in our Web.Core project in order to be able to use .Include()
.
Is this by design? Or would your recommend a better approach to avoid a full table scan for SingleResult OData queries?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Depends how you map
Id
.Try: