Base solution for your next web application
Open Closed

Compile error on cache get function #9887


User avatar
0
fawad29 created
  • What is your product version?
  • 10 Latest
  • What is your product type (Angular or MVC)?
  • ASP.net Core and Angular
  • What is product framework type (.net framework or .net core)?
  • .NET5
  • What is ABP Framework version?
  • The one that comes up with ASP.NET and Angular v10.

I am upgrading from version 8.0.0.0 to version 10.0.0.0. The code mentioned in the image below works fine on version 8, however I am getting compile time error on version 10. Has something changed on cache retrieval mechanism? I am passing a dto.

The code is the same, as I have copied and pasted the complete file.

Version 8 - Works fine

Version 10 - Compile error

I see from change logs on GitHub that methods belonging to CacheExtensions had been removed in March. What should be the alternative in my case, as I need to pass dto to my function?

Please see below the code which works fine on version 8, I need to convert this so that it works fine on version 10, please provide guidance or example code.

public async Task<List<AccommodationTypesListDto>> GetAll(GetFilteredAccommodationTypeInputDto getFilteredAccommodationTypeInputDto)
{
    var cacheName = _nebulaCacheManager.GetTenantCacheName(_accommodationTypeCache.CacheName);

    var accommodationType = await _cacheManager
     .GetCache(cacheName)
     .Get(getFilteredAccommodationTypeInputDto, () => GetAllFromDB(getFilteredAccommodationTypeInputDto));

    return ObjectMapper.Map<List<AccommodationTypesListDto>>(accommodationType.OrderBy(getFilteredAccommodationTypeInputDto.Sorting));

}

private async Task<List<AccommodationTypesListDto>> GetAllFromDB(GetFilteredAccommodationTypeInputDto getFilteredAccommodationTypeInputDto)
{

var accommodationTypes = await (from accommodationType in _accommodationTypeRepository.GetAll()
                            .Where(a => a.MyField1 = getFilteredAccommodationTypeInputDto.MyField1 &&
                            a.MyField2 = getFilteredAccommodationTypeInputDto.MyField2)

               select new AccommodationTypesListDto
               {
                   Id = accommodationType.Id,
                   Text = accommodationType.Text,
                   DisplayOrder = accommodationType.DisplayOrder,
                   TenantId = accommodationType.TenantId

               }).ToListAsync();
return accommodationTypes;

}

Can you help with example code please?


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You should use AsTyped after the GetCache call. Similar to usage below;

    return _cacheManager
            .GetCache(cacheName)
            .AsTyped<string, AccommodationTypesListDto>()
            .Get(getFilteredAccommodationTypeInputDto, () => GetAllFromDB(getFilteredAccommodationTypeInputDto));
    
  • User Avatar
    0
    fawad29 created

    Thanks, works fine now.