在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