AutoMapper 3.1.1 and Entity Framework 6.1 Proxy objects

耗尽温柔 提交于 2019-12-01 09:26:24

You are using Automapper incorrectly, you need to use the QueryableExtensions namespace, so your code should be

IQueryable<Company> companies = CompaniesService.FindCompanies();

CompanyListItem[] results = companies.Project().To<CompanyListItem>().ToArray();

Also if you where going to do it the other way you still had Mapper.Map wrong, it should have been

IQueryable<Company> companies = CompaniesService.FindCompanies();

CompanyListItem[] result = Mapper.Map<IEnumerable<Company>,CompanyListItem[]>(companies);

but I still recommend doing the .Project().To<T>() method as it will perform the mapping server side instead of client side so you potentially have less data that needs to be sent over the wire.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!