在Web Api控制器中考虑以下方法:
[Queryable(AllowedQueryOptions= AllowedQueryOptions.All)]
public override IQueryable<Mandate> Get()
{
return new List<Mandate>() { new Mandate() {
Id = 1,
PolicyNumber = "350000000",
OpenPositions = new List<OpenPosition>(){
new OpenPosition(){ Id = 1, Amount =2300 },
new OpenPosition(){ Id = 2, Amount =2100 }
}},
new Mandate() {
Id = 2,
PolicyNumber = "240000000" ,
OpenPositions = new List<OpenPosition>(){
new OpenPosition(){ Id = 3, Amount =2500 },
new OpenPosition(){ Id = 2, Amount =2100 }
}
} }.AsQueryable<Mandate>();
}
此处列表是手动构建的,如果我浏览到以下URL:
http://localhost:52446/odata/Mandates?$filter=Id eq 1
它会从列表中返回正确的项目。
现在很明显,列表更可能是数据库结构。将使用某些ORM检索数据并将其返回到Web API服务。
我不使用Entity Framework(我不能因为遗留系统)。
在这种情况下,我如何使用Web API?如何翻译url参数,以便负责数据访问的层应用过滤器?
答案 0 :(得分:0)
知道了。您通过LINQ提供程序向我指出了正确的方向。我发现我可以使用我们正在使用的ORM(OpenAccess)轻松完成。更多信息:http://docs.telerik.com/data-access/developers-guide/using-web-services/asp.net-web-api/developer-guide-wcfservices-web-api-expose-oacontext