C# 如何在OData服务中向IEdmModel添加多个名称空间

C# 如何在OData服务中向IEdmModel添加多个名称空间,c#,odata,asp.net-web-api,C#,Odata,Asp.net Web Api,目前,我正在使用带有WebApi的OData,我一直坚持在WebApiConfig文件中的IEdmModel GetModel()中添加多个名称空间。下面是我目前使用的方法 public static IEdmModel GetModel() { ODataModelBuilder builder = new ODataConventionModelBuilder(); var product= builder.EntitySet&

目前,我正在使用带有WebApi的OData,我一直坚持在WebApiConfig文件中的
IEdmModel GetModel()
中添加多个名称空间。下面是我目前使用的方法

public static IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

           var product= builder.EntitySet<Product>("Products");
            //product.EntityType.HasKey(pkg => pkg.ID);
            //product.EntityType.HasKey(pkg => pkg.Code);

            builder.EntitySet<Customer>("Customers");
            builder.EntitySet<CustomerAddress>("CustomerAddresses");
            builder.EntitySet<CustomerEmail>("CustomerEmails");
            builder.EntitySet<CustomerPhone>("CustomerPhones");
            builder.EntitySet<Country>("Countries");
            builder.EntitySet<State>("States");
            builder.EntitySet<CustomerStore>("CustomerStores");

            builder.Namespace = "StateService";
            builder.EntityType<State>().Collection.Function("GetStatesByCountry").ReturnsCollectionFromEntitySet<State>("States");

            builder.Namespace = "ProductCategoryService";
            builder.EntityType<ProductCategory>().Collection.Function("GetProductCategories").ReturnsCollectionFromEntitySet<ProductCategory>("ProductCategories");


            return builder.GetEdmModel();
        }

我的问题是有没有办法避免这个问题。非常感谢任何帮助

WebAPI OData可以为每个entityType、complexType设置名称空间,例如:

// Set the default namespace 
builder.Namespace = "Default";
builder.EntitySet<Product>("Products");

var prodType = builder.EntityType<Product>();
// Set the namespace for type product
prodType.Namespace = "ProductNamespace";
//设置默认名称空间
builder.Namespace=“Default”;
建筑商实体集(“产品”);
var prodType=builder.EntityType();
//设置product类型的命名空间
prodType.Namespace=“ProductNamespace”;

这对我不起作用-你能提供完整的例子吗?我正在尝试实现这一点,但失败得很厉害。这是怎么回事?你能详细说明你是如何解决的吗?我正在尝试你接受的答案,但似乎无法让它工作。
// Set the default namespace 
builder.Namespace = "Default";
builder.EntitySet<Product>("Products");

var prodType = builder.EntityType<Product>();
// Set the namespace for type product
prodType.Namespace = "ProductNamespace";