我目前正在实施WebApi。我基本上需要填充数据库中的所有产品并使用EntityFramework数据库First Approach。我需要在提供程序类中自动化我的Buisness对象和Data对象。无论如何,我收到以下错误
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"}
这是我的数据对象
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();
}
}
}
这是我的Provider类,我实现了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 :(得分:0)
你需要把它写成你的模型类:
公共类产品:IMapFrom&lt; YourBusnessEntityToMap&gt;
现在它会正常工作。 :)