我正在尝试将业务对象映射到数据优先的自动生成实体。但是,我在我返回的映射器类中遇到错误new Lab
。
错误是"Cannot Convert expression type 'LabManager.DataAcces.Lab' to return type LabManager.BusinessObjects.BusinessObjects.Lab"
我的问题是:当我在映射器类中返回它所期望的内容时,为什么会出现这个错误?
我的业务对象如下所示:
namespace LabManager.BusinessObjects.BusinessObjects
{
public class Lab
{
public Lab()
{
}
public int Id { get; set; }
public string Name { get; set; }
public IList<Cylinder> Cylinders { get; set; }
}
}
我将业务对象映射到的实体是:
public partial class Lab
{
public Lab()
{
this.Cylinders = new HashSet<Cylinder>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Cylinder> Cylinders { get; set; }
}
而且我只是使用手动映射器类(没有 AutoMapper):
namespace EmitLabManager.DataAccess.ModelMapper
public class Mapper
{
internal static BusinessObjects.BusinessObjects.Lab GetLabs(Lab entity)
{
return new Lab
{
Id = entity.Id,
Name = entity.Name,
Cylinders = entity.Cylinders
};
}
}