Activities of "s.beckers"

I think this needs to be checked in the commercial source code.

Description

Static template synchronization appears to use the wrong definition ID when deleting existing content, causing duplicate rows in AbpTextTemplateDefinitionContentRecords.

This was observed on ABP 10.4.1, with up to 14 records for the same (DefinitionId, FileName), and independently reproduced using the published Volo.Abp.TextTemplateManagement.Domain 10.7.1 package.

Reproduction

An isolated console test executes the actual package’s synchronization logic with in-memory repository proxies:

  1. Start with an existing template definition and one content record (en.tpl).
  2. Supply the same template and content with newly generated IDs, as produced during serialization.
  3. Include an additional new template definition to trigger persistence.
  4. Execute synchronization twice.

The existing template’s content grows from 1 → 2 → 3 records, all sharing the same persisted definition ID and filename.

This reproduction does not require a database. It does not imply that every unchanged application restart inserts duplicates.

Expected behavior

Synchronization replaces existing static content, leaving one current record per definition and filename.

Actual behavior and suspected cause

In StaticTextTemplateSaver.UpdateChangedTemplatesAsync, the deletion uses:

await TextTemplateContentRepository.DeleteByDefinitionIdAsync(record.Key.Id);

Here, record.Key.Id is the newly generated definition ID. Existing content belongs to templateRecordInDatabase.Id, so the deletion removes nothing.

The incoming content is subsequently assigned to templateRecordInDatabase.Id and inserted, leaving the previous records in place.

The deletion should presumably use the persisted definition ID:

await TextTemplateContentRepository.DeleteByDefinitionIdAsync(
    templateRecordInDatabase.Id);

Could you confirm this issue and provide a fix, together with guidance for safely cleaning up existing duplicate records?

Environment

  • OS: Windows
  • Runtime: .NET 10
  • Database: EF Core with SQL Server for the original observation
  • Verified package versions: 10.4.1 and 10.7.1
  • Isolated reproduction: Actual ABP package with in-memory repository proxies

Hi @EngincanV,

Hi, since in your entity configuration the UserProfile has a not nullable UserId field you can't set the user.Profile as null without deleting the userProfile.

Added a new DeleteProfile method in user repository:

public class EfCoreUserRepository : EfCoreRepository<AbpEFCorePlaygroundDbContext, User, Guid>, IUserRepository
{
    public EfCoreUserRepository(
        IDbContextProvider<AbpEFCorePlaygroundDbContext> dbContextProvider)
        : base(dbContextProvider)
    {
    }

    public async Task DeleteProfileAsync(User user)
    {
        if (user.Profile == null)
        {
            return;
        }

        AbpEFCorePlaygroundDbContext dbContext = await GetDbContextAsync();
        dbContext.Remove(user.Profile);

        user.Profile = null;
    }
}

Update in app service:

public async Task DeleteUserProfileAsync()
{
    var user = await _userRepository.GetAsync(x => x.Id == Guid.Parse("c64b873e-c067-43e0-ae00-07992a880837"));

    if (user.Profile == null)
    {
        return;
    }

    await _userRepository.DeleteProfileAsync(user);

    await _userRepository.UpdateAsync(user);
}

The user updated event is correct: But when I continue after the breakpoint, the request still keeps executing, because of the infinite loop in the AbpDbContext: And the user profile is not deleted in the database.

Best regards, Steff Beckers

Hi @EngincanV,

I've reverted the changes in the app service.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpEFCorePlayground.Users;

public class UsersAppService : AbpEFCorePlaygroundAppService, IUsersAppService
{
    private readonly IUserRepository _userRepository;

    public UsersAppService(IUserRepository userRepository)
    {
        _userRepository = userRepository;
    }

    public async Task DeleteUserProfileAsync()
    {
        var user = await _userRepository.GetAsync(x => x.Id == Guid.Parse("c64b873e-c067-43e0-ae00-07992a880837"));

        if (user.Profile == null)
        {
            return;
        }

        user.Profile = null;
        
        await _userRepository.UpdateAsync(user);
    }
}

I've been debugging the AbpDbContext, after I execute the delete user profile request, I can toggle between these 2 breakpoints as an infinite loop: AbpDbContext ApplyAbpConceptsForModifiedEntity(EntityEntry entry, bool forceApply = false) AbpDbContext ApplyAbpConceptsForDeletedEntity(EntityEntry entry) The entry.Reload(); is responsible for the non-stop querying in this case.

Best regards, Steff Beckers

Hi @EngincanV,

I've updated the AbpEFCorePlayground example app: https://cdn.fuzed.app/share/abp/AbpEFCorePlayground.zip

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace AbpEFCorePlayground.Users;

public class UsersAppService : AbpEFCorePlaygroundAppService, IUsersAppService
{
    private readonly IRepository<UserProfile, Guid> _userProfileRepository;
    private readonly IUserRepository _userRepository;

    public UsersAppService(
        IRepository<UserProfile, Guid> userProfileRepository,
        IUserRepository userRepository)
    {
        _userProfileRepository = userProfileRepository;
        _userRepository = userRepository;
    }

    public async Task DeleteUserProfileAsync()
    {
        var user = await _userRepository.GetAsync(x => x.Id == Guid.Parse("c64b873e-c067-43e0-ae00-07992a880837"));

        if (user.Profile == null)
        {
            return;
        }

        await _userProfileRepository.DeleteAsync(user.Profile);
    }
}

I have added an event handler for User aggregate updates:

using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;

namespace AbpEFCorePlayground.Users;

public class UserEventHandlers : IDistributedEventHandler<EntityUpdatedEto<UserEto>>, ITransientDependency
{
    public Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData)
    {
        return Task.CompletedTask;
    }
}

The user profile is deleted in the database now, but not in the events. Also, in our main project we disabled adding repositories for all entities, we only have repositories for aggregate roots:

context.Services.AddAbpDbContext<AbpEFCorePlaygroundDbContext>(options =>
{
        /* Remove "includeAllEntities: true" to create
         * default repositories only for aggregate roots */
    options.AddDefaultRepositories(includeAllEntities: true);
});

We removed "includeAllEntities: true". In this case we can't use IRepository<UserProfile, Guid>. A workaround for this could be adding a Task DeleteProfileAsync(User user) method to the IUserRepository (accessing the DbContext), but also doesn't fix the issue related to the event, since user.Profile is still filled.

Best regards, Steff Beckers

Hi @EngincanV,

and make the UserId as nullable

A UserProfile record can't exist without a reference to a User, so the UserId on UserProfile should not be nullable.

Best regards, Steff Beckers

Hi @EngincanV,

Hi, based on your EfCorePlayground project, you can call _context.UserProfiles.Remove(user.Profile!) method before setting user.Profile to null:

The EfCorePlayground project doesn't have the issue, the AbpEfCorePlayground project has.

Best regards, Steff Beckers

Hi @EngincanV,

If you want to do this with repository pattern, then you should inject the profile repository and use its DeleteAsync method:

I tried this approach, but it still results in the API non-stop spamming the database with queries.

I've executed the API endpoint for 1 minute, then stopped the API.

SQL Server Profiler output, with 15k of the same queries as result.

Hi @EngincanV,

I have the following User aggregate root:

public class User : FullAuditedAggregateRoot<Guid>
{
    public User(
        Guid id,
        string name)
    {
        Id = id;
        Name = name;
    }

    private User()
    {
    }

    public string Name { get; set; }

    public UserProfile? Profile { get; set; }
}

I also have an User record in my database (via IDataSeedContributor):

User user = new User(
    id: Guid.Parse("c64b873e-c067-43e0-ae00-07992a880837"),
    name: "Steff Beckers")
{
    Profile = new UserProfile()
    {
        Bio = "Software Developer"
    }
};

await _userRepository.InsertAsync(user);

Now I want to delete the user's profile. What I'm thinking is:

var user = await _userRepository.GetAsync(userId);

user.Profile = null;

await _userRepository.UpdateAsync(user);

But this results in the error. How else should I delete the user's profile?

Best regards, Steff Beckers

Hi @EngincanV,

Any progress on this issue?

Best regards, Steff Beckers

Showing 1 to 10 of 49 entries
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v11.1.0-preview. Updated on November 20, 2026, 13:33
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.