c# - FullAuditedEntity,对象映射器 : CreatorUserId Null when Creating New Entry or Deleting

标签 c# asp.net-web-api objectmapper object-object-mapping asp.net-boilerplate

我一直通过 API 将数据发布到经过全面审核的实体。就这样FullAuditedEntity ,它应该使用 CreatorId、creationTime 和其他几个列值自动创建。但是当我检查数据库时,CreatorUserIDnull 即使CreationTime有没有。它应该是 1因为我使用默认管理员发布了。此外,当我删除行时,也会发生同样的情况:我只能看到 DeletionTime但不是DeleterUserId .

下面是我可以使用断点看到的 API 端点捕获的数据:

enter image description here

我尝试了两种对象映射方法创建 outputoutput2他们都给出相同的 null CreatorUserId 的值 。没错,都是CreatorUserIdCreationTime到这个阶段应该已经有了值(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.

CreatorUserIdCreationTime 仅在调用 SaveChanges() 后才具有值。

I have to put [TenantId] manually in the JSON post object, and it shows in the database.

你不应该这样做。 CreatorUserIdonly 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/

相关文章:

c# - 使用 RegularExpressionAttribute 时客户端验证不起作用

javascript - 将对象从 Ajax 传递到 C# WebApi

c# - GraphQL 为 .net 开发做好准备

java - 如何使用 Jackson 的 ObjectMapper.readerForUpdating 忽略某些字段

java - 使用 Jackson API 将 JSON 记录转换为 LinkedHashMap<String,String>

c# - 控制沿路径移动的非运动学刚体

c# - 创建上划线文本

c# - react 性扩展 : Is it possible to subscribe on Sum of the result of Buffer operation?

java - @jsonview 在未知属性上失败

security - Web-api 安全 : SSL?