使用ODataConventionModelBuilder及其EntitySet<>功能,是否可以重命名实体集上的属性名称?
假设我有一个实体集类型Foo. 它有两个属性,Bar和Baz。但是,在我的 OData 模型中,我希望属性分别命名为Jack和Jane。我可以这样做吗?
我希望有这样的事情:
var builder = new ODataConventionModelBuilder { Namespace = "Blah" };
var foo = builder.EntitySet<Foo>("Foo");
foo.AliasProperty(f => f.Bar, "Jack");
foo.AliasProperty(f => f.Baz, "Jane");
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直无法找到可以做到这一点的东西。
在使用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 = …Run Code Online (Sandbox Code Playgroud)