Nic*_*los 5 asp.net entity-framework dto automapper asp.net-web-api
我正在尝试使用自动映射器将IQueryable <entity>映射到IQueryable <entityDTO>,以生成Linq。我正在使用实体框架和oracle 11g的Web API项目。
public virtual IQueryable<TDto> Get()
{
IQueryable<TEntity> EntObjs;
EntObjs = GenericService.Get();
var Dtos = EntObjs.Project().To<TDto>();
return Dtos;
}
Run Code Online (Sandbox Code Playgroud)
只要Tentity类型中没有任何集合,它就可以正常工作。我在http://www.devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code中找到了信息,该信息已经解决了一半。我知道我可以使用跟随功能使用Automapper映射集合,但是我需要将它放在linq中,这样我才不会打断Iquerable链。
Mapper.Map<TSource, TDestination>(Source,Destincation);
Run Code Online (Sandbox Code Playgroud)
您可以在查询链中使用它。
例如:
EntObjs.Project(). Select(x=> Mapper.Map(x))...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1291 次 |
| 最近记录: |