Automapper on HotChocolate Optional types #3925
-
Source/destination types// Source
public class TagInput
{
public int? Id { get; set; }
public Optional<string> Name { get; set; }
public Optional<int?> TagTypeId { get; set; }
}
// Destination
public class Tag
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
public int TagTypeId { get; set; }
public virtual TagType TagType { get; set; }
} Mapping configurationpublic class TagInputProfile : Profile
{
public TagInputProfile()
{
CreateMap<TagInput, Tag>()
.ForMember(dest => dest.Id, opt => opt.Condition(src => src.Id.HasValue))
.ForMember(dest => dest.Name, opt => {
opt.PreCondition(src => src.Name.HasValue);
opt.MapFrom(src => src.Name.Value);
})
.ForMember(dest => dest.TagTypeId, opt => {
opt.PreCondition(src => src.TagTypeId.HasValue);
opt.MapFrom(src => src.TagTypeId.Value);
})
.EqualityComparison((d, s) => d.Id == s.Id)
.ReverseMap();
}
} Version:Automapper: 8.1.1 Expected behaviorTo be able to map Optional type to the destination. Right now it just keeps throwing this error on run:
Note that only Nullable does not work. The string type is working since I did not enable nullable reference types. Even nullable reference type was enabled, its still throwing the same error. I am not sure what's causing the error. I actually expect the above mapping code to work since the precondition will only map those if Actual behaviorIt throws the error above. Steps to reproduceNot sure if this is the correct step to reproduce but the error was thrown when var configuration = new MapperConfiguration(config =>
{
config.AddCollectionMappers();
config.AddMaps("Horsebee.API");
});
services.AddSingleton(sp => configuration.CreateMapper()); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
A repro would help. Make a gist that we can execute and see fail. That means the only reference must be to the latest AM. Everything else must be part of the gist. |
Beta Was this translation helpful? Give feedback.
A repro would help. Make a gist that we can execute and see fail. That means the only reference must be to the latest AM. Everything else must be part of the gist.