- ABP Framework version: v8.2.0
- UI Type: Blazor Server
- Database System: EF Core (SQL Server)
- Tiered (for MVC) or Auth Server Separated (for Angular): tiered
On appservice we are getting data as list. After getting list, we change property value using for loop. We get successfully excepted result on UI and in list. Additionally row that related that data at sql also changes.
public virtual async Task<PagedResultDto<CityWithNavigationPropertiesDto>> GetListAsync(GetCitiesInput input)
{
var totalCount = await _cityRepository.GetCountAsync(input.FilterText, input.Name, input.IsActive, input.CountryId);
var items = await _cityRepository.GetListWithNavigationPropertiesAsync(input.FilterText, input.Name, input.IsActive, input.CountryId, input.Sorting, input.MaxResultCount, input.SkipCount);
var tmp = items.FirstOrDefault();
tmp.City.Name = "newValue";
return new PagedResultDto<CityWithNavigationPropertiesDto>
{
TotalCount = totalCount,
Items = ObjectMapper.Map<List<CityWithNavigationProperties>, List<CityWithNavigationPropertiesDto>>(items)
};
}
For test purposes, as you see above code we assing 'newValue' first item of list. It is okey, it changes. But it also changes database row of it. We also disable UOW, but result is same. On appservice we just get list , not create or update entity, despite this it updates value.
--------------------------------------------------------------------------------------------- By the way, we renewed our license but our ticket count did not renew to 30.
5 Answer(s)
-
0
hi
Please try to map your entities to
CityWithNavigationProperties
then change the value inCityWithNavigationProperties
.ObjectMapper.Map<List<CityWithNavigationProperties>, List<CityWithNavigationPropertiesDto>>(items)
By the way, we renewed our license but our ticket count did not renew to 30.
Please send an email to info@abp.io
-
0
hi We tried your method but it did not work. We also tried
AsnoTracking
method. It worked. As you see previous code block, we make just get process. So even if ef core tracks the entities, it should not change database value. Why database updates occur? To prevent data corruption should we always useAsNoTracking
method while getting list? is there any performance effect usingAsNoTracking
on project. -
0
hi
Have you tried this?
public virtual async Task<PagedResultDto<CityWithNavigationPropertiesDto>> GetListAsync(GetCitiesInput input) { var totalCount = await _cityRepository.GetCountAsync(input.FilterText, input.Name, input.IsActive, input.CountryId); var items = await _cityRepository.GetListWithNavigationPropertiesAsync(input.FilterText, input.Name, input.IsActive, input.CountryId, input.Sorting, input.MaxResultCount, input.SkipCount); var dto = ObjectMapper.Map<List<CityWithNavigationProperties>, List<CityWithNavigationPropertiesDto>>(items); var tmp = dto.FirstOrDefault(); tmp.City.Name = "newValue"; return new PagedResultDto<CityWithNavigationPropertiesDto> { TotalCount = totalCount, Items = dto }; }
Of course if you don't want to change the entities, You can inject the
Read-Only Repositories
see https://github.com/abpframework/abp/pull/17421
-
0
When mapping to
CityWithNavigationPropertiesDto
, it worked. Also usingAsNoTracking
prevented changing. Thanks for reply. -
0
great