AutoMapperMappingException:缺少类型映射配置或不支持的映射。类的匿名类型

时间:2020-07-29 17:45:24

标签: c# asp.net automapper core

这是我的Acquirer Model类,我在其中管理请求属性

const clik = () => {
  props.click(input);
  setInput({ titel: "", content: "" });
};

这是我的响应类AcquirerDTO.cs,在那里我可以获取所有响应

       public class Acquirer{
              public string MERCHANTNO {get;set;}
              public float TRANSACTIONAMOUNT{get;set;}
              public DateTime PROCESSDATE{get;set;}
              
           public Acquirer(){}

           public Acquirer(float TRANSACTIONAMOUNT,DateTime PROCESSDATE,string MERCHANTNO){
                     this.TRANSACTIONAMOUNT=TRANSACTIONAMOUNT;
                     this.PROCESSDATE=PROCESSDATE;       
                     this.MERCHANTNO=MERCHANTNO;
           }

我的AutoMapperClass

AutoMapper.cs

       public class AcquirerDTO{
              public string MERCHANTNO {get;set;}
              public float TRANSACTIONAMOUNT{get;set;}
              public DateTime PROCESSDATE{get;set;}
          }

}

这是完成映射的地方,我收到此错误映射类型: <> f__AnonymousType2`2 []-> AcquirerDTO

 public class AutoMapping : Profile
{
    public AutoMapping()
    {
        CreateMap<Acquirer, AcquirerDTO>(); 
    }
}

1 个答案:

答案 0 :(得分:0)

我是这样完成的

var datasendd = datasend
           .GroupBy(s => new { s.MerchantNo, s.ProcessDate })
           .Select(g =>
              new Acquirer
              {
                  PROCESSDATE = g.Key.ProcessDate,
                  TransactionAmountSum = g.Sum(x => x.TransactionAmount)
              }).ToArray();


            List<AcquirerDTO> listDest = _mapper.Map<Acquirer[], List<AcquirerDTO>>(datasendd);