Skip to content

Ignoring properties that are nullable in the source but not nullable in the target #3941

Discussion options

You must be logged in to vote

Hello guys, I think authors won't help me. I solved my problem like this way, I hope this can help you.

    public class Tests
    {
        MapperConfiguration CreateConfiguration() => new(cfg =>
        {
            cfg.CreateMap<Source, Destination>()
                .ForMember(x => x.Age2, y => y.MapFrom(new IgnoreNullValueResolver<int?, int>(), x => x.Age))
                .IgnoreAllNull();
        });
        [SetUp]
        public void Setup()
        {
        }

        [Test]
        public void Test1()
        {
            var config = CreateConfiguration();
            var mapper = config.CreateMapper();
            var s1 = new Source {Age = 5, Time = DateTime.Now.AddDays(1…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sinanakyazici
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #3940 on March 16, 2022 19:56.