我想使用一个GetData
获取一些数据。该商业方法从控制器通过这个行动方法的服务层叫做:无法将服务层实体映射到域模型实体
public PartialViewResult Grid()
{
var model = new DomainModels.Reports.MeanData();
using (var reportsClient = new ReportsClient())
{
model = reportsClient.GetData(reportType, toDate, fromDate); //<= error on this line
}
return PartialView("_Grid", model);
}
我得到这个错误:
Cannot implicitly convert type '
System.Collections.Generic.List<BusinessService.Report.MeanData>
' to 'DomainModels.Reports.MeanData
'
一位同事曾使用Automapper这个建议,所以我改变了行动方法是这样的基础上,他什么工作:
public PartialViewResult Grid()
{
using (var reportsClient = new ReportsClient())
{
Mapper.CreateMap<DomainModels.Reports.MeanData, BusinessService.Report.MeanData>();
var model = reportsClient.GetData(reportType, toDate, fromDate);
DomainModels.Reports.MeanData viewModel = //<= error on this line
Mapper.Map<DomainModels.Reports.MeanData, BusinessService.Report.MeanData>(model);
}
return PartialView("_Grid", viewModel);
}
我得到这个错误:
The best overloaded method match for '
AutoMapper.Mapper.Map<DomainModels.Reports.MeanData,BusinessService.Report.MeanData>
(DomainModels.Reports.MeanData)' has some invalid arguments
的的DomainModel实体:
用相同的名称的DomainModel实体[DataContract]
public class MeanData
{
[DataMember]
public string Description { get; set; }
[DataMember]
public string Month3Value { get; set; }
[DataMember]
public string Month2Value { get; set; }
[DataMember]
public string Month1Value { get; set; }
}
设置businessService实体,其可以在所生成的reference.cs
发现由具有属性。
我在这两种情况下做错了什么?
@lazyberezovsky:我想你的答案,并得到了错误:'无法隐式转换类型“System.Collections.Generic.List”到“系统.Collections.Generic.List '' –
Animesh