ビジネス オブジェクトをデータ ファーストの自動生成エンティティにマップしようとしています。ただし、マッパークラスでエラーが発生し、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
};
}
}