我有需要了解两天之间差异的情况。我想在mapper conf
中这样做。在自动映射器映射(UseValue)中计算日期时间差异
问题是我不知道这是可能的和如何?
下面是示例代码:
CreateMap<Post, ManagePostViewModel>()
.ForMember(d => d.ActiveInDays, conf => conf.UseValue((DateTime.UtcNow - (conf.CreatedAt)).TotalDays));
我测试了这个语法静态值和它的作品。如果我使用conf.CreatedAt
它不到风度,给人以下错误:
'IMemberConfigurationExpression' does not contain definition for 'CreatedAt' and no extension method 'CreatedAt' accepting a first argument of type 'IMemberConfigurationExpression' could be found (are you missing a using directive or an assembly reference?)
在model
和viewModel
我已经定义CreatedAt
。
您键入了'conf.CreatedAt'。这不是你的ViewModel,这是'IMemberConfigurationExpression'对象,它允许你创建一个表达式 –