0

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

1 に答える 1

1

名前空間の競合が発生している可能性があります。GetLabs 関数でコンストラクターを完全修飾する必要があります。

return new BusinessObjects.BusinessObjects.Lab
    {
         Id = entity.Id,
         Name = entity.Name,
         Cylinders = entity.Cylinders
    };

これでうまくいくはずです。

于 2013-02-26T15:45:27.273 に答える