【发布时间】:2020-04-03 08:54:41
【问题描述】:
我目前在尝试映射数据对象时遇到错误,如下所示;
Method 'get_Item' in type 'Proxy_System.Collections.Generic.IList`1[[InsureAfrika_API.Model.DataModel, InsureAfrika API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]_28141317_' from assembly 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' does not have an implementation.
以下是我的数据源; QuoteSourceDto
public string ResponseStatus { get; set; }
public IList<Data> Data { get; set; }
数据类
public string Client { get; set; }
public IList<Extensions> Extensions { get; set; }
扩展源类
public Decimal Limit { get; set; }
public Decimal Rate { get; set; }
我的目的地班; QuoteDestinationModel
public string ResponseStatus { get; set; }
public IList<DataModel> Data { get; set; }
数据模型
public string Client { get; set; }
public IList<ExtensionsModel> Extensions { get; set; }
ExtensionModel 类
public Decimal Limit { get; set; }
public Decimal Rate { get; set; }
以下是我的映射器配置;
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<IList<Extensions>, IList<ExtensionsModel>>();
cfg.CreateMap<IList<Data>, IList<DataModel>>();
cfg.CreateMap<QuoteSourceDto, QuoteDestinationModel>()
.ForMember(dest => dest.Data, opt => opt.MapFrom(src => src.Data))
.ForMember(dest => dest.ResponseStatus, opt => opt.Ignore());
})
我的数据源;
IList<Extensions> exts =new List<Extensions>
{
new Extensions{Rate=1.34M,Limit=21400.00M};
}
IList<Data> dat = new List<Data>
{
new Data{Client="Micael Angelus", Extensions =exts};
};
QuoteSourceDto dtos = new QuoteSourceDto
{
ResponseStatus = "Success",
Data = dat
};
因此我的 Map 函数调用如下所示;
var _client = mapper.Map<QuoteSourceDto, QuoteDestinationModel>(dtos);
当我使用List 类型时,它不会返回任何错误,也不会返回一个空列表,而当我使用IList 时,它会返回上述错误。我要做的就是将结果映射到 QuoteDestinationModel。
编辑 我正在使用 Automapper 版本 9.0.0
【问题讨论】:
-
我已经用他们的文档调试了 3 小时,但我仍然没有弄清楚为什么会出现这个错误。
-
网上有很多例子。尝试 AM 存储库中的测试。
-
这不是答案
标签: c# automapper