隐藏OData对象

时间:2015-09-02 12:04:54

标签: c# entity-framework asp.net-web-api odata

假设你有这样的代码:

var builder = new ODataConventionModelBuilder { Namespace = "Blah" };
var foo = builder.EntitySet<Foo>("Foo");
var bar = builder.EntitySet<Foo>("Bar");

(注意它们都是Foo类型,但具有不同的端点名称(Foo / Bar)。

我知道我可以通过这样做隐藏属性:

foo.EntityType.Ignore(f => f.Baz);

但是,当通过Bar端点访问它时,它也会隐藏属性。 (大概是因为它隐藏在基础类型本身之外)

是否有某种方法可以仅为各个端点隐藏属性,而不是从基础类型本身隐藏属性?

编辑:

在使用EntityType.Ignore()后,我还尝试使用各种Has*方法添加内容,例如foo.HasManyBinding(f => f.Baz),但此时尝试访问该属性会出现以下错误:

{
  "error":{
    "code":"","message":"No HTTP resource was found that matches the request URI 'http://localhost:58799/odata/Foo(42)/Baz'.","innererror":{
      "message":"No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'.","type":"","stacktrace":""
    }
  }
}

0 个答案:

没有答案