2016-04-11 5 views
0

現在WebApiを実装中です。基本的には、データベースからすべての製品を取り込み、EntityFrameworkデータベースのFirst Approachを使用する必要があります。私はプロバイダクラスのBuisnessオブジェクトとDataオブジェクトを自動化する必要があります。しかしそう、私は次のようなエラーにAutomapper error-タイプマップの設定が欠落しているか、サポートされていないマッピング

Missing type map configuration or unsupported mapping.\r\n\r\nMapping types:\r\nProducts -> Products\r\nProductManagement.DataOjects.Entities.Products -> 
ProductManagement.Models.Products\r\n\r\nDestination path:\r\nIEnumerable`1[0]\r\n\r\nSource value:\r\nProductManagement.DataOjects.Entities.Products"} 

を得るここに私のDataObject

namespace ProductManagement.DataOjects.Entities 
{ 
    public class Products 
    { 
     public int Id { get; set; } 

     public string Name { get; set; } 

     public string Code { get; set; } 

     public DateTime ReleaseDate { get; set; } 
     } 
} 

は、ここに私のグレードってこんなモンオブジェクト

namespace ProductManagement.Models 
{ 
    public class Products 
    { 
     public int Id { get; set; } 

     public string Name { get; set; } 

     public string Code { get; set; } 

     public DateTime ReleaseDate { get; set; } 
    } 
} 

はここで取得するためにLINQを使用して、私のリポジトリクラスがあるされていますデータ

public class ProductRepository : IProductRepository 
    { 
     public IEnumerable<ProductManagement.DataOjects.Entities.Products> GetProductData() 
     { 
      using (var dbProductEntities = new ProductManagement.DataOjects.Ef.RansangEntities()) 
      { 
       return (from a in dbProductEntities.vw_Products 
         select new ProductManagement.DataOjects.Entities.Products 
         { 
          Id = a.Id, 
          Name = a.Name, 
          Code = a.Code, 
          ReleaseDate = (DateTime)a.ReleaseDate 

         }).ToList().AsEnumerable(); 
      } 
     } 


    } 

は、ここで私は誰かが、問題がどうなるか教えてもらえますAutomapper

public class ProductProvider : IProductProvider 
    { 
     private readonly IProductRepository _productRepository; 


     public ProductProvider(IProductRepository productRepository) 
     { 
      _productRepository = productRepository ; 
     } 

     public IEnumerable<Products> GetProductData() 
     { 
      var productData = _productRepository.GetProductData(); 
      var productViewData = AutoMapper.Mapper.Map<IEnumerable<ProductManagement.DataOjects.Entities.Products>, IEnumerable<ProductManagement.Models.Products>>(productData); 
      return productViewData; 

     } 


    } 

を実装している私のプロバイダクラスですか?

+0

「CreateMap」を使ってどこにでもマッピングを定義しましたか? – PatrickSteele

+0

いいえ。あなたも持っていますか?どこでどのように行うのか教えてください。 – Tom

+0

参照:https://github.com/AutoMapper/AutoMapper/wiki/Projection – PatrickSteele

答えて

0

あなたのモデルクラスにようにそれを記述する必要があります。

パブリッククラス製品:IMapFrom < YourBusnessEntityToMap>

今では正常に動作します。 :)

関連する問題