Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

CreatorUserId not set #10968


User avatar
0
OutdoorEd created

We are using ASP.NET Zero v11 and we're running into an issue where the CreatorUserId is not being filled in.

The application doesn't use the service classes for its custom work. The entities inherit from FullAuditedEntity which includes CreatorUserId. In our code, we create such an entity using a mapping from a view model. In the below code, Statement is an entity that inherits from FullAuditedEntity. IStatementRepository gets injected. private readonly IStatementRepository _repoStatement;

var theEntity = _objectMapper.Map(model);

theEntity.Statement = model.Statement.CleanHtml();

await _repoStatement.InsertAsync(witnessStatementEntity);

The repo:

public interface IStatementRepository : IRepository<Statement, Guid> { }

<br> public classStatementRepository : OE_TenantRepositoryBase<Statement, Guid>, IStatementRepository {     public StatementRepository(IDbContextProvider<OE_TenantDbContext> dbContextProvider) : base(dbContextProvider)     {     } }

<br/> In an old(er) version of the codebase, so based on an older version of ASP.NET Zero, without setting the value for the CreatorUserId, this seemed to work fine and so the framework set this value automatically. However, in the current version, this seems not to be the case anymore.

We can set the value manually before calling the insert on the repo but if the entity inherits from FullAuditedEntity, shouldn't this value be set automatically by the framework? If so (which it's not doing right now), can this be enabled somehow?


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

    Hi @outdoored

    Is this code called in an AppService or in a background job ?

  • User Avatar
    0
    OutdoorEd created

    This code is used directly in this case in the controller.

  • User Avatar
    0
    musa.demir created

    Hi @outdoored

    I could not reproduce it in the clean AspNetZero project. It saves CreatorUserId as expected.

    Can you please share more code part with us so that we can reproduce it?