我試圖將業務對象映射到數據優先自動生成的實體。然而,Iam在我的mapper類中得到一個錯誤,我返回new Lab
。將映射的業務對象返回到EF實體部分類時出錯
的錯誤是"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
};
}
}
爲什麼你只在方法聲明中使用完整類型名稱,而不是在任何地方使用? – Kniganapolke 2013-02-26 15:43:04
@Kniganapolke這是一個很好的問題。我想我應該。我以前從來沒有真正需要這樣的資格。我通常會盡量保持對象名稱的獨特性,因此不必以此方式進行限定。我很可能會重構名稱和冗餘名稱空間(BusinessObjects.BusinessObjects)。 – 2013-02-26 15:54:56