没有实体框架的WebAPI ODATA

Sam*_*Sam 7 odata asp.net-web-api

在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>();
    }
Run Code Online (Sandbox Code Playgroud)

这里列表是手动构建的,如果我浏览到以下url:

http://localhost:52446/odata/Mandates?$filter=Id eq 1 它从列表中返回正确的项目.

现在很明显,列表更可能是数据库结构.将使用某些ORM检索数据并将其返回到Web API服务.

我不使用实体框架(我不能因为遗留系统).

在这种情况下,我如何使用Web API?如何翻译url参数,以便负责数据访问的层应用过滤器?

Sam*_*Sam 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