-2

Let's say I have an EF Core model with these three properties:

public int Id { get; set; }
public string? ApplicationName { get; set; }
public string? ApplicationVersion { get; set; }

and in the automapper output, after calling ProjectTo I want it to map to Output:

public NameAndVersion {
    public string? Name { get; set; }
    public string? Version { get; set; }
}

public Output {
    public int Id { get; set; }
    public NameAndVersion? Application { get; set; }
}

is there a way to accomplish that?

Gargoyle
  • 9,590
  • 16
  • 80
  • 145

1 Answers1

1

Although ProjectTo has a restricted list of features, this one is can be set up via a regular MapTo.

CreateMap<YourEFmodel, Output>()
    .ForMember(
        dest => dest.Application,
        opt => opt.MapFrom(
            src => new NameAndVersion 
            {
                Name = src.ApplicationName,
                Version = src.ApplicationVersion
            }
        ));
pfx
  • 20,323
  • 43
  • 37
  • 57