如何将多个命名空间添加到 OData 服务中的 IEdmModel
How to add multiple namespaces into IEdmModel in OData service
目前我正在使用带有 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();
}
如果我先添加另一个命名空间,它会覆盖
builder.Namespace = "StateService";
builder.Namespace = "ProductCategoryService";
我的问题是有什么方法可以避免这个问题。任何帮助将不胜感激
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";
目前我正在使用带有 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();
}
如果我先添加另一个命名空间,它会覆盖
builder.Namespace = "StateService";
builder.Namespace = "ProductCategoryService";
我的问题是有什么方法可以避免这个问题。任何帮助将不胜感激
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";