[Tutorial & Sample] Using Parameter Alias to simplify the OData URL


Are you suffering from typing complex parameter values in URL? Or even make it worse you need to type it more than once?

To solve this problem, now Microsoft.OData.Core.dll 6.0 supports parameter alias in request URL, such as: ~/People?$filter=LastName eq @name and contains(Description, @name)&@name=’Bob’

It is implemented by introducing a new class: ParameterAliasNode and its base class is SingleValueNode. The alias (@name) is parsed into a ParameterAliasNode.

Note: This blog assumes that you have writing ODL server side code experience.

But how to leverage this feature? Just 3 steps:

1. Create an instance of ODataUriParser as normal:

2. Update the node visitor to support ParameterAlliasNode:

3. Call the visitor to translate the node tree into expression:

Then execute the Linq Express as normal, that’s it.


Comments (3)

  1. Jim Skimming says:

    I follow this blog through RSS, but because you're using GitHub to host your code snippets, they don't appear in the feed.

    Scott Hanselman has a post describing some options:

    http://www.hanselman.com/…/BestCodeSyntaxHighlighterForSnippetsInYourBlog.asp

    Can you please use a format that is as accessible as possible?

  2. Jim Skimming says:

    The previous link was truncated, here is the correct link.

    http://www.hanselman.com/…/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx

  3. Joseph2nite/jbd says:

    ALIAS//U Who The hell is this

    – ……..