OData中实体的别名

OData中实体的别名

本文介绍了OData中实体的别名/重命名属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using the ODataConventionModelBuilder and its EntitySet<> functionality, is it possible to rename the names of properties on the entity sets?

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

Let's say I have an entity set type, Foo. It has two properties, Bar and Baz. However, in my OData model, I'd like the properties to instead to named Jack and Jane, respectively. Can I do this?

我希望这样的东西:

var builder = new ODataConventionModelBuilder { Namespace = "Blah" };
var foo = builder.EntitySet<Foo>("Foo");
foo.AliasProperty(f => f.Bar, "Jack");
foo.AliasProperty(f => f.Baz, "Jane");

到目前为止,我一直找不到这样做。

So far I've been unable to find something that does this.

推荐答案

是的,你可以。基于:

var builder = new ODataConventionModelBuilder { Namespace = "Blah" };
var foo = builder.EntitySet<Foo>("Foo");
foo.Property(f => f.Bar).Name = "Jack";
foo.Property(f => f.Baz).Name = "Jane";

尽管如此,我一直无法使用此导航属性。

I've been unable to use this for navigation properties though.

这篇关于OData中实体的别名/重命名属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:31