简体   繁体   English

使用自动映射器将 map 整个 object 用于枚举

[英]Use automapper to map entire object to an enum

Is it possible to use automapper to determine an enum for the entire object?是否可以使用自动映射器确定整个 object 的枚举? Now I get this error:现在我得到这个错误:

Missing type map configuration or unsupported mapping.缺少类型 map 配置或不支持的映射。

When I try like当我尝试像

var orderType = _mapper.Map<OrderType>(orderData);

What I've been trying is:我一直在尝试的是:

public class Mapper : Profile
{
    public Mapper()
    {
        CreateMap<OrderData, OrderType>()
            .ConvertUsing(s => OrderType.Type1);
    }
    public enum OrderType { Type1, Type2, Type3 }
}

Of course there will be some more logic later to determine the correct enum:-)当然,稍后会有更多逻辑来确定正确的枚举:-)

I did a mistake at startup so it never added the profile to automapper我在启动时犯了一个错误,所以它从未将配置文件添加到 automapper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM