question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make nullables dublicates of the mappings (And ignore settings of my mapper)

See original GitHub issue

Following the documentation - i made internal mapper to convert properties of the object:

[Mapper(UseDeepCloning = true)]
public static partial class PortfolioMapper
{
    public static partial GetPortfolioResponseDto ToGetDto(this Portfolio source);

    [MapperIgnoreSource(nameof(Agreement.Portfolios))]
    [MapperIgnoreSource(nameof(Agreement.Client))]
    private static partial GetAgreementResponseDto ToGetAgreementResponseDto(Agreement source);

    [MapperIgnoreSource(nameof(Client.Agreements))]
    private static partial GetClientResponseDto ToGetClientResponseDto(Client source);
}

Code Generated includes “?” for nullables for the Portfolio class image

But also for the Agreement class where i configured ignore settings for the Client property: image

So it uses nullable version of code-generated mapper and doesn’t pick up my configuration.

To Reproduce So I’ve tried to reproduce the bug, but in small project it works fine - it doesn’t create nullable duplicates.

Environment (please complete the following information):

  • Mapperly Version: 2.6
  • Target Framework: net7.0
  • OS: Windows10

Original Classes:

public class Agreement
{
    [Key]
    public int AgreementId { get; set; }

    public Client Client { get; set; }
    public string Code { get; set; }
    public List<Portfolio> Portfolios { get; set; }
    public DateTimeOffset Date { get; set; }
    public DateTimeOffset? TerminationDate { get; set; }

    public bool IsDeleted { get; set; }
}

public sealed class GetAgreementResponseDto
{
    public int AgreementId { get; init; }
    public GetClientResponseDto Client { get; init; }
    public string Code { get; init; }
    public DateTimeOffset Date { get; init; }
    public DateTimeOffset TerminationDate { get; init; }
}
public sealed class GetPortfolioResponseDto
{
    public int PortfolioId { get; init; }
    public GetAgreementResponseDto Agreement { get; init; }
    public string Code { get; init; }
    public DateTimeOffset Date { get; init; }
    public DateTimeOffset TerminationDate { get; init; }
}

public class Portfolio 
{
    [Key]
    public int PortfolioId { get; set; }

    public Agreement Agreement { get; set; }
    public string Code { get; set; }
    public DateTimeOffset Date { get; set; }
    public DateTimeOffset? TerminationDate { get; set; }

    public bool IsDeleted { get; set; }
}

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
latonzcommented, Jan 31, 2023

I found a bug related to init only properties and nullable. should be fixed with #257.

0reactions
github-actions[bot]commented, Mar 13, 2023

🎉 This issue has been resolved in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoMapper MapFrom can't take null values [duplicate]
It has to be possible to assign a null value. How can I fix it so that I can assign null values to...
Read more >
Automapper Update entity field if not null fails ...
Ignore does two things - skips mapping if the members match, and skip the member for configuration validation. If you need to skip...
Read more >
Scaffold mapping on non-nullable bool #10840
The columns are not null and have a default in the DB. Can't the scaffold be smart enough to allow me to set...
Read more >
Fluent API - Configuring and Mapping Properties and Types
In this article. Model-Wide Settings; Property Mapping; Type Mapping; Model Used in Samples. When working with Entity Framework Code First the ...
Read more >
Chapter 2. Mapping Entities
The name property is mapped to the flight_name column, which is not nullable, has a length of 50 and is not updatable (making...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found