Gui*_*rot 6 c# asp.net odata asp.net-web-api
在使用OData的ASP .NET Web API中,我有一个C#对象描述了允许在$ filter中使用的字段
假设我想$filter
仅限制支持$filter=deviceId gt 'someValue'
(遵循http://www.ben-morris.com/parsing-odata-queries-decoupled-data-entities-webapi/ approach ...).
所以我定义了这样一个类:
[DataContract]
public class DeviceODataQuery
{
[DataMember(Name = "deviceId")]
public string DeviceId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我自己构建OData上下文因为我不能使用IQueryable
(太长时间来解释原因,它的遗留代码......).
它看起来像这样:
/* Configure supported fields for query */
var builder = new ODataConventionModelBuilder();
builder.EntitySet<DeviceODataQuery>("DeviceODataQuery");
builder.Namespace = typeof(DeviceODataQuery).Namespace;
var model = builder.GetEdmModel();
ODataQueryContext = new ODataQueryContext(model, typeof(DeviceODataQuery));
/* Configure supported OData parameters for validation */
ODataValidationSettings.AllowedFunctions = AllowedFunctions.None;
ODataValidationSettings.AllowedLogicalOperators = AllowedLogicalOperators.GreaterThan;
ODataValidationSettings.AllowedArithmeticOperators = AllowedArithmeticOperators.None;
ODataValidationSettings.AllowedQueryOptions = AllowedQueryOptions.Top | AllowedQueryOptions.Filter;
Run Code Online (Sandbox Code Playgroud)
长话短说,我现在可以$filter=DeviceId gt 'someValue'
在我的请求中使用,但它拒绝使用注释中的名称,我不能使用deviceId
...
似乎注释被忽略了,有没有其他方法来做或修复我的代码使注释工作?
归档时间: |
|
查看次数: |
780 次 |
最近记录: |