5

I'm trying to map IQueryable< entity> to IQueryable< entityDTO> using Automapper for generating Linq. I'm working on a Web API project w/ entity framework and oracle 11g.

public virtual IQueryable<TDto> Get() 
{
IQueryable<TEntity> EntObjs;
EntObjs = GenericService.Get();     
var Dtos = EntObjs.Project().To<TDto>();
return Dtos;
}

It works fine as long as the Tentity type does not have any Collections in it. I found info at http://www.devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code that has got be halfway to solving the problem. I know I can map the collections with Automapper using the follow function, but I need it to be in linq so I do not break the Iquerable chain.

Mapper.Map<TSource, TDestination>(Source,Destincation);
4

1 回答 1

0

您可以在查询链中使用它。

例如:

EntObjs.Project(). Select(x=> Mapper.Map(x))...

于 2012-08-09T15:21:31.860 回答