Closed ghaith100994 closed 3 years ago
This was already fixed in the new release. Which version of the nuget package are you using?
rc-3
public async Task<TDto> GetByIdAsync<T, TDto>(Guid entityId, BaseSpecification<T> specification, CancellationToken cancellationToken = default)
where T : BaseEntity
where TDto : IDto
{
string cacheKey = CacheKeys.GetCacheKey<T>(entityId);
byte[] cachedData = !string.IsNullOrWhiteSpace(cacheKey) ? await _cache.GetAsync(cacheKey, cancellationToken) : null;
if (cachedData != null)
{
await _cache.RefreshAsync(cacheKey, cancellationToken);
var entity = _serializer.Deserialize<TDto>(Encoding.Default.GetString(cachedData));
return entity;
}
else
{
IQueryable<T> query = _dbContext.Set<T>();
if (specification != null)
query = query.Specify(specification).Where(a => a.Id == entityId);
var entity = await query.FirstOrDefaultAsync(cancellationToken: cancellationToken);
var dto = entity.Adapt<TDto>();
if (dto != null)
{
if ((specification?.Includes?.Count == 0) || specification == null)
{
var options = new DistributedCacheEntryOptions();
byte[] serializedData = Encoding.Default.GetBytes(_serializer.Serialize(dto));
await _cache.SetAsync(cacheKey, serializedData, options, cancellationToken);
}
return dto;
}
throw new EntityNotFoundException(string.Format(_localizer["entity.notfound"], typeof(T).Name, entityId));
}
}
here when specification is null no filtering is done
Please check RC 4 . This bug was fixed. Do let me know if you face any additional issues related to this. Thanks
https://www.nuget.org/packages/FullStackHero.WebAPI.Boilerplate/0.0.4-rc
the bug still exit in the RC 4
I think you have fixed it for this function
public async Task<T> GetByIdAsync<T>(Guid entityId, BaseSpecification<T> specification = null, CancellationToken cancellationToken = default)
not the other one
public async Task<TDto> GetByIdAsync<T, TDto>(Guid entityId, BaseSpecification<T> specification, CancellationToken cancellationToken = default)
the answer if (specification != null) query = query.Specify(specification).Where(a => a.Id == entityId); else query = query.Where(a => a.Id == entityId);
Thanks for pointing it out. Could you test it now? I have added the changes.
Please pull the latest code from the repository and try.
Thanks It's Work
public async Task GetByIdAsync<T, TDto> in Repositories Class return first item of table if speciation has not been initialize