相关疑难解决方法(0)

OData 中实体的别名/重命名属性

使用ODataConventionModelBuilder及其EntitySet<>功能,是否可以重命名实体集上的属性名称?

假设我有一个实体集类型Foo. 它有两个属性,BarBaz。但是,在我的 OData 模型中,我希望属性分别命名为JackJane。我可以这样做吗?

我希望有这样的事情:

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)

到目前为止,我一直无法找到可以做到这一点的东西。

c# entity-framework odata asp.net-web-api

6
推荐指数
2
解决办法
3467
查看次数

OData实体属性序列化名称不同于C#变量名称

在使用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)

c# asp.net odata asp.net-web-api

6
推荐指数
0
解决办法
780
查看次数

标签 统计

asp.net-web-api ×2

c# ×2

odata ×2

asp.net ×1

entity-framework ×1