I am trying to get some data using one GetData
. This business method is called from the controller through a service layer in this Action method:
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);
}
I get this error:
Cannot implicitly convert type '
System.Collections.Generic.List<BusinessService.Report.MeanData>
' to 'DomainModels.Reports.MeanData
'
A colleague had suggested using Automapper for this, so I changed the Action method like this, based on what worked for him:
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);
}
I get this error:
The best overloaded method match for '
AutoMapper.Mapper.Map<DomainModels.Reports.MeanData,BusinessService.Report.MeanData>
(DomainModels.Reports.MeanData)' has some invalid arguments
The DomainModel entity:
[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; }
}
The BusinessService entity, which can be found in the generated reference.cs
is having properties with same names as the DomainModel entity.
What am I doing wrong in both instances?