User-671945816 posted
I have an Microsoft.Odata.Edm.IEdmModel and I am trying to determine what EntitySet each operation belongs to. But it doesn't seem possible. I tried the following:
var edm = WebApiConfig.GetOdataEdmModel();
var operation = edm.SchemaElements.First(x => (x as IEdmOperation)?.Name == "GetRecentCustomers") as IEdmOperation;
var boundTo = operation.FindParameter("bindingParameter");
var matchingEntitySets = edm.EntityContainer.EntitySets()
.Where(x => x.Type.FullTypeName() == boundTo.Type.Definition.FullTypeName())
.ToList();
The problem is that matchingEntitySets can have more than one result. The reason is that the OData model is built this way:
e.g.,
var builder = new ODataConventionModelBuilder();
builder.EntitySet<BusinessEntity>("Customers");
builder.EntitySet<BusinessEntity>("Vendors");
builder.EntityType<BusinessEntity>()
.Collection
.Function(nameof(CustomersController.GetRecentCustomers))
.ReturnsCollectionFromEntitySet<BusinessEntity>("Customers");
Is the answer simply that OData doesn't support more than one entity set with the same model type? If that is the case why doesn't the builder protect against this?