在OpenRasta中是否有可能讓Uri模式允許提交相同鍵值的數組並將其映射到接受查詢參數數組的處理程序方法。在OpenRasta中,是否可以匹配多個鍵/值對?
示例:從集合中返回名爲Dave Smith的所有聯繫人。
HTTP GET /觸點filterBy =第一& filterValue =戴維& filterBy =最後& filterValue =史密斯
用的配置:
什麼語法將是最適合的URI的字符串模式匹配? (建議歡迎)
ResourceSpace.Has.ResourcesOfType<List<ContactResource>>()
.AtUri("/contacts")
.And.AtUri("/contacts?filterBy[]={filterBy}[]&filterValue[]={fv}[]") // Option 1
.And.AtUri("/contacts?filterBy={filterBy}[]&fv={fv}[]") // Option 2
將映射到的處理程序方法:
public object Get(params Filter[] filters)
{
/*
create a Linq Expression based on the filters using dynamic linq
query the repository using the Linq
*/
return Query.All<Contact>().Where(c => c.First == "Dave" && c.Last == "Smith").ToResource()
}
其中過濾器由下式定義
public class Filter
{
public string FilterBy { get; set; }
public string FilterValue { get; set; }
}
您好斯科特,您是否最終找到了解決方案?需要做類似的事情。 – 2010-11-30 12:19:47