MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.29k stars 327 forks source link

Can't generate combined model #557

Open DifficultNick opened 1 year ago

DifficultNick commented 1 year ago

I am trying to generate a model that will combine two classes (named MainContext and TechContext). So I've created another class that contains two properties of this classes:

public class CombinedContext
{
    public MainContext MainContext { get; set; }
    public TechContext TechContext { get; set; }
}

and this is my config:

public class MapsterConfig : ICodeGenerationRegister
{
    public void Register(CodeGenerationConfig config)
    {
        config.AdaptTo("FullContext")
            .ForType<CombinedContext>(
            cfg =>
            {
                cfg.Map(res => res, src => src.MainContext);
                cfg.Map(res => res, src => src.TechContext);
            });
    }
}

like in the bottom of mapping instructions page so, when I run dotnet mapster model -a "assembly.dll" I got an error: Allow only first level member access (eg. obj => obj.Name) (Parameter 'lambda')

How can I do this correctly? Thank you for help and for this product!