Created
September 9, 2013 18:40
-
-
Save raghuramn/6499741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); | |
builder.EntitySet<Customer>("Customers"); | |
HttpConfiguration config = new HttpConfiguration(); | |
config.Routes.MapODataRoute("odata", "", builder.GetEdmModel()); | |
HttpServer server = new HttpServer(config); | |
HttpClient client = new HttpClient(server); | |
var response = client.GetAsync("http://localhost/Customers?$select=Name").Result; | |
Console.WriteLine(response); | |
Console.WriteLine(response.Content.ReadAsStringAsync().Result); | |
} | |
} | |
public class CustomersController : ODataController | |
{ | |
public IEnumerable<Customer> Get(ODataQueryOptions<Customer> query) | |
{ | |
Customer[] customers = new[] { new Customer { ID = 42, Name = "Raghu" } }; | |
// Apply query | |
var result = customers; | |
// set the SelectExpandClause on the request to hint the odata formatter to | |
// select/expand only the fields mentioned in the SelectExpandClause. | |
if (query.SelectExpand != null) | |
{ | |
Request.SetSelectExpandClause(query.SelectExpand.SelectExpandClause); | |
} | |
return result; | |
} | |
} | |
public class Customer | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment