我收到此錯誤:AutoMapper - AutoMapperMappingException:錯誤映射類型
AutoMapperMappingException: Error mapping types.
Mapping types: Game -> VirtualGame
InvalidOperationException: Nullable object must have a value.
Property: Timing lambda_method(Closure , object , object , ResolutionContext)
AutoMapperMappingException: Error mapping types.
我想我已經追查到下面的代碼塊。有沒有辦法在這個塊中檢查null,以便這個錯誤消失?
cfg.CreateMap<Game, VirtualGame>()
.ForMember(d => d.GameTiming, opt =>
{
opt.Condition(s => s.GameStartTime != null && s.GameEndTime != null);
opt.MapFrom(
s => new Timing(s.GameStartTime.Value, s.GameEndTime.Value, s.GameDuration));
})
哦,這就是 「時機」 是:
public Timing(DateTime gameStartTime, DateTime gameEndTime, Int32?
gameDuration = null)
謝謝!這是否取代我的opt.Condition聲明? – SkyeBoniwell
是的,它的確如此。更新。 –