[转]Composite Keys With WebApi OData
本文转自:http://chris.eldredge.io/blog/2014/04/24/Composite-Keys/
In our basic configuration we told the model builder that our entity has a composite key comprised of an ID and a version:
1 |
|
This is enough for our OData feed to render edit
and self
links for each individual entity in a form like:
http://localhost/odata/Packages(Id='Sample',Version='1.0.0')
But if we navigate to this URL, instead of getting just this one entity by key, we get back the entire entity set.
To get the correct behavior, first we need an override on our PackagesODataController that gets an individual entity instance by key:
1 |
|
However, out of the box WebApi OData doesn’t know how to bind composite key parameters to an action such as this, since the key is comprised of multiple values.
We can fix this by creating a new routing convention that binds the stuff inside the parenthesis to our route data map:
1 |
|
This class decorates a standard EntityRoutingConvention
and splits the raw key portion of the URI into key/value pairs and adds them all to the routeValues dictionary.
Once this is done the standard action resolution kicks in and finds the correct action overload to invoke.
This routing convention was adapted from the WebApi ODataCompositeKeySampleproject.
Here we see another difference between WebApi OData and WCF Data Services. In WCF Data Services, the framework handles generating a query that selects a single instance from an IQueryable
. This limits our ability to customize how finding an instance by key is done. In WebApi OData, we have to explicitly define an overload that gets an entity instance by key, giving us more control over how the query is executed.
This distinction might not matter for most projects, but in the case of NuGet.Lucene.Web, it enables a mirror-on-demand capability where a local feed can fetch a package from another server on the fly, add it to the local repository, then send it back to the client as if it was always there in the first place.
To customize this in WCF Data Services required significant back flips.
Series Index
[转]Composite Keys With WebApi OData的更多相关文章
- [转]Web API OData V4 Keys, Composite Keys and Functions Part 11
本文转自:https://damienbod.com/2014/09/12/web-api-odata-v4-keys-composite-keys-and-functions-part-11/ We ...
- OData – the best way to REST–实例讲解ASP.NET WebAPI OData (V4) Service & Client
一.概念介绍 1.1,什么是OData? 还是看OData官网的简单说明: An open protocol to allow the creation and consumption of quer ...
- AspNet WebApi OData 学习
OData介绍:是一个查询和更新数据的Web协议.OData应用了web技术如HTTP.Atom发布协议(AtomPub)和JSON等来提供对不同应用程序,服务 和存储的信息访问.除了提供一些基本的操 ...
- AspNet.WebAPI.OData.ODataPQ
AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务 AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务-(个人拙笔) AspNet. ...
- AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务-(个人拙笔)
AspNet.WebAPI.OData.ODataPQ 这是针对 Asp.net WebAPI OData 协议下,查询分页.或者是说 本人在使用Asp.Net webAPI 做服务接口时写的一个分页 ...
- 主攻ASP.NET MVC4.0之重生:Asp.Net MVC WebApi OData
1.新建MVC项目,安装OData Install-Package Microsoft.AspNet.WebApi.OData -Version 4.0.0 2.新建WebAPI Controller ...
- AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务-(个人拙笔)(转)
出处:http://www.bubuko.com/infodetail-827612.html AspNet.WebAPI.OData.ODataPQ 这是针对 Asp.net WebAPI ODat ...
- [转]OData – the best way to REST–实例讲解ASP.NET WebAPI OData (V4) Service & Client
本文转自:http://www.cnblogs.com/bluedoctor/p/4384659.html 一.概念介绍 1.1,什么是OData? 还是看OData官网的简单说明: An open ...
- webAPi OData的使用
一.OData介绍 开放数据协议(Open Data Protocol,缩写OData)是一种描述如何创建和访问Restful服务的OASIS标准. 二.OData 在asp.net mvc中的用法 ...
随机推荐
- c# async 事物
上菜 async await 机制 确实便捷开发 多线程时 如何一致性如何保证呢? public async Task<ActionResult<IEnumerable<stri ...
- Python(模块&包)
参考:https://www.cnblogs.com/yuanchenqi/articles/5732581.html 在linux下给pycharm安装第三方库,需要在.bashrc中加: 因为对应 ...
- C++中运算符的优先级
运算符挺多的,很难一一记住他们的优先级,在此去别人博客复制以下内容,供自己以后学习. 优先级 运算符 含 义 要求运算 对象的个数 结合方向 1 () [] -> . 圆括号 下标运算符 ...
- 爬虫实战4:用selenium爬取淘宝美食
方案1:一次性爬取全部淘宝美食信息 1. spider.py文件如下 __author__ = 'Administrator' from selenium import webdriver from ...
- multiprocessor(下)
一.数据共享 展望未来,基于消息传递的并发编程是大势所趋即便是使用线程,推荐做法也是将程序设计为大量独立的线程集合,通过消息队列交换数据.这样极大地减少了对使用锁定和其他同步手段的需求,还可以扩展到分 ...
- Centos7.4下安装Nginx
一.下载Nginx Nginx下载地址:http://nginx.org/en/download.html Nginx是C语言开发的,建议在Linux上运行.由于Nginx的一些模块依赖一些lib,所 ...
- Java多线程——对象组合
我们不希望对每一次的内存访问都进行分析以确保程序是线程安全的,而是希望将一些现有的线程安全组件组合为更大规模的组件或者程序,这里介绍一些组合模式,这些组合模式能够使一个类更容易成为线程安全的,并且在维 ...
- knova绘制矩形
效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- js字符串去重
js字符串去重: 1. 去掉字符串前后所有空格: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } ...
- destoon调用方法汇总 ---转载
根目录.模板目录和样式目录:{DT_PATH}{DT_SKIN}导入头脚:{template 'header'}{template 'footer'}对应模块首页:{$MODULE[$moduleid ...