ODataConventionModelBuilder

ODataConventionModelBuilder

本文介绍了如何防止ODataConventionModelBuilder自动公开所有派生类型的元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ODataConventionModelBuilder来为Web API OData服务构建Edm模型,如下所示:

I'm using ODataConventionModelBuilder to build Edm Model for Web API OData Service like this:

ODataModelBuilder builder = new ODataConventionModelBuilder();

builder.Namespace = "X";

builder.ContainerName = "Y";

builder.EntitySet<Z>("Z");

IEdmModel edmModel = builder.GetEdmModel();

Z 类位于一个程序集中,并且从 Z 派生的公共 Q 不同的组装.

Class Z is located in one assembly, and there is public class Q derived from Z located in different assembly.

ODataConventionModelBuilder将生成 Edm模型,该模型包括 Q 的定义(以及其他派生类),并将与服务元数据一起公开.在我们的情况下,这是不可取的.

The ODataConventionModelBuilder will generates Edm Model that includes definition of class Q (among other derived classes) and it will be exposed with service metadata. That is undesirable in our case.

当派生类无法访问(例如,定义为内部)时,这种问题肯定不存在.

When derived class in inaccessible (e.g. defined as internal) such problem, sure, doesn't exist.

是否可以强制ODataConventionModelBuilder不自动公开所有派生类型的元数据?

Is there way to force the ODataConventionModelBuilder to do NOT automatically expose all derived types' metadata?

推荐答案

这应该有效:

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

builder.Namespace = "X";

builder.ContainerName = "Y";

builder.EntitySet("Z");

builder.Ignore<Q>();

IEdmModel edmModel = builder.GetEdmModel();

这篇关于如何防止ODataConventionModelBuilder自动公开所有派生类型的元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 13:20