这个问题在这里已经有一个答案:>
Web API Queryable – how to apply AutoMapper?4个
我有一个ASP.NET WebAPI项目.我最近为所有的数据表创建了EntityFramework实体.但我不想暴露我的数据层和模式给我的用户如何将我的实体映射到viewmodel(automapper?)并提供IQueryable返回类型,以便我的API支持OData?
我有一个ASP.NET WebAPI项目.我最近为所有的数据表创建了EntityFramework实体.但我不想暴露我的数据层和模式给我的用户如何将我的实体映射到viewmodel(automapper?)并提供IQueryable返回类型,以便我的API支持OData?
OData支持查询组合和类似sql的参数.我想我需要为查询组合部分提供某种2路翻译?这是否意味着自定义LINQ提供程序?我希望它比这更容易.
还是应该放弃IQueryable / OData?
解决方法
我在这里找到答案:
Web API Queryable – how to apply AutoMapper?
而不是使用[Queryable],您可以使用类型为ODataQueryOptions< T>对您想要的任何类型或LINQ查询应用OData操作.这是一个很好的例子,甚至不需要使用AutoMapper:
public virtual IQueryable<PersonDto> Get(ODataQueryOptions<Person> odataQuery){ odataQuery.Validate(new ODataValidationSettings(){ AllowedFunctions = AllowedFunctions.AllMathFunctions }); var people = odataQuery.ApplyTo(uow.Person().GetAll()); return ConvertToDtos(people); }
这是the Microsoft page解释这个用法的细节. (大约一半下)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。