Mark Tabor

Mark Tabor

  • 569
  • 1.9k
  • 430.7k

AutoMapper in c# using MVC

Nov 4 2020 1:56 AM
Hi I am implementing automapper in my c# mvc project i am following this tutorial
 
https://www.c-sharpcorner.com/article/web-api-crud-operations-and-consume-service-in-asp-net-mvc-application/
 
but i am getting error as shown below i have check my entiry model and model class my columns are same
 
"Getting this error on foreach loop Missing type map configuration or unsupported mapping. Mapping types: Product -> Product DataAccessLayer.Product -> API.Models.Product Destination path: Product Source value: DataAccessLayer.Product"
 
below are my classes
  1. public class EntityMapper<TSource, TDestination> where TSource : class where TDestination : class  
  2. {  
  3. public EntityMapper()  
  4. {  
  5. Mapper.CreateMap<Models.Product, Product>();  
  6. Mapper.CreateMap<Product, Models.Product>();  
  7. }  
  8. public TDestination Translate(TSource obj)  
  9. {  
  10. return Mapper.Map<TDestination>(obj);  
  11. }  
  12. }
  1. public partial class Product  
  2. {  
  3. public int ProductId { getset; }  
  4. public string ProductName { getset; }  
  5. public Nullable<int> Quantity { getset; }  
  6. public Nullable<int> Price { getset; }  
  7. }
  1. public int ProductId { getset; }  
  2. public string ProductName { getset; }  
  3. public Nullable<int> Quantity { getset; }  
  4. public Nullable<int> Price { getset; }
I am getting error on this line
  1. foreach (var item in prodList)  
  2. {  
  3. products.Add(mapObj.Translate(item));  
  4. }
exception is Missing type map configuration or unsupported mapping.

Answers (3)