【发布时间】:2016-05-20 23:49:04
【问题描述】:
鉴于以下简单的 OData 4 控制器(请参见下文),我如何 $select 仅城市?
http://localhost//api/Customers?$select=Location
给我:
{
"@odata.context":"http://localhost/api/$metadata#Customers(Location)","value":[
{
"Location":{
"Country":"Ireland","City":"Sligo"
}
},{
"Location":{
"Country":"Finland","City":"Helsinki"
}
}
]
}
但我不知道如何深入挖掘,以便获得城市。这甚至可能吗?
public class CustomersController : ODataController
{
private List<Customer> customers = new List<Customer>()
{
new Customer
{
CustomerId = 1,
Location = new Address
{
City = "Sligo",
Country = "Ireland"
}
},
new Customer
{
CustomerId = 2,
Location = new Address
{
City = "Helsinki",
Country = "Finland"
}
}
};
[EnableQuery]
public List<Customer> Get()
{
return customers;
}
}
【问题讨论】:
标签: asp.net-web-api odata