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 andNo 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:
- Copy BookStore example
- Add AuthorRepository_Tests to Acme.BookStore.EntityFrameworkCore.Tests
- Follow documentation to disable tracking ( try global or context specific ( SettingManagementDbContext ), both doesnt work )
- Run Test
- 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