Ends in:
2 DAYS
2 HRS
39 MIN
52 SEC
Ends in:
2 D
2 H
39 M
52 S
Open Closed

Unable to update, UseQueryTrackingBehavior has no effect #3317


User avatar
0
cala created

Issue: https://github.com/abpframework/abp/issues/13110

  • Your ABP Framework version: 5.3
  • Your database provider(EF Core/MongoDB): EF Core
  • Exception message and stack trace if available (check the logs): The instance of entity type 'Setting' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values. for global and No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext. for specific
  • Steps needed to reproduce the problem:
  1. Copy BookStore example
  2. Add AuthorRepository_Tests to Acme.BookStore.EntityFrameworkCore.Tests
  3. Follow documentation to disable tracking ( try global or context specific ( SettingManagementDbContext ), both doesnt work )
  4. Run Test
  5. See exception

SettingsRepository_Tests.cs:

using System;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.SettingManagement;
using Xunit;

namespace Acme.BookStore.EntityFrameworkCore.Samples;

public sealed class AuthorRepository_Tests : BookStoreEntityFrameworkCoreTestBase
{
	private readonly ISettingRepository _settingRepository;

	public AuthorRepository_Tests()
	{
		_settingRepository = GetRequiredService<ISettingRepository>();
	}
	
	[Fact]
	public async Task Should_Not_Track()
	{
		const string name1 = "Settings1";
		const string name2 = "Settings2";
		const string value = "A";
	        
		await WithUnitOfWorkAsync( async () =>
		{
			// Arrange
			Guid settingId = Guid.NewGuid();
			Setting setting1 = new( settingId, name1, value );
			Setting setting2 = new( settingId, name2, value );
		        
			// Act
			await _settingRepository.InsertAsync( setting1, true );
			Setting resultSetting1 = await _settingRepository.GetAsync( settingId );
			await _settingRepository.UpdateAsync( setting2, true );
			Setting resultSetting2 = await _settingRepository.GetAsync( settingId );
		        
			// Assert
			resultSetting1.ShouldNotBeNull();
			resultSetting2.ShouldNotBeNull();
			resultSetting1.Name.ShouldBe( name1 );
			resultSetting2.Name.ShouldBe( name2 );
		} );
	}
}

For more details, please check the github issue


No answer yet!
Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35