我一直通过 API 将数据发布到经过全面审核的实体。就这样FullAuditedEntity
,它应该使用 CreatorId、creationTime 和其他几个列值自动创建。但是当我检查数据库时,CreatorUserID
是 null
即使CreationTime
有没有。它应该是 1
因为我使用默认管理员发布了。此外,当我删除行时,也会发生同样的情况:我只能看到 DeletionTime
但不是DeleterUserId
.
下面是我可以使用断点看到的 API 端点捕获的数据:
我尝试了两种对象映射方法创建 output
和output2
但他们都给出相同的 null
CreatorUserId
的值 。没错,都是CreatorUserId
和CreationTime
到这个阶段应该已经有了值(value)。
[AbpAuthorize]
public async Task<Rule> CreateAsync(CreateRuleInput input)
{
Rule output = Mapper.Map<CreateRuleInput, Rule>(input);
Rule output2 = ObjectMapper.Map< Rule>(input);
return await _ruleManager.Create(output);
}
我的对象映射函数有什么问题吗?
最佳答案
您的对象映射函数没有任何问题。
I experimented with two Object Mapping Methods... By right, both CreatorUserId and CreationTime should have values by this stage.
CreatorUserId
和 CreationTime
仅在调用 SaveChanges()
后才具有值。
I have to put [TenantId] manually in the JSON post object, and it shows in the database.
你不应该这样做。 CreatorUserId
是 only set if the entity belongs to the current tenant .
I can see UserId which is 1 in breakpoint. Somehow it gets ignored during mapping.
将实体创建为“默认”租户管理员的正确方法是以租户管理员身份登录。
UserId = 1
表示您以主持人管理员身份登录。 “默认”租户管理员具有 UserId = 2
。
If I don't specify tenantId or put 0, it gives Server Internal Error: 500.
如果您希望主机创建规则
,请确保它实现IMayHaveTenant
而不是IMustHaveTenant
。
关于c# - FullAuditedEntity,对象映射器 : CreatorUserId Null when Creating New Entry or Deleting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48109095/