2014-01-08 18 views
0

我在POST方法中返回IQueriable<Dictionary<string,string>>。我希望能夠在字典上應用OData過濾器。例如:來自字典的webapi過濾器屬性<string,string>

詞典

Key = Place 
Value = New York 

my filter is ?$filter=Place eq 'New York' 

**

But I get an error: ":"Instance property 'Place' is not defined for type 'System.Collections.Generic.Dictionary`2[System.String

**

+0

請提供您的代碼和示例數據:-) – Yoeri

回答

0

找到第三方lib的解決方案。 LinqToQuerystring

var queryValue = Request.RequestUri.ParseQueryString(); return _dictionary.LinqToQuerystring(queryValue.ToString());

0

我想你可以通過創建一個名爲 '位置' 一個GET方法更簡單的解決您的問題,使用名爲key的參數並返回在該控制器的Dictionary實例中查找key值的結果。事情是這樣的:

[HttpGet] 
public string Places(string key) { 
    //TODO: Handle validation of value key parameter & missing keys 
    return _placesDictionary[key]; 
} 

IQueryable實施旨在對抗強類型集合工作。你是僞代碼顯示你打算通過鍵值查詢字典。

IQueryable<Dictionary<string,string>>實際上定義了一個收集Dictionary<string,string>實例。您看到的錯誤絕對正確,Dictionary類型中沒有名爲Place的屬性。