Scenario1
In this scenario, I would like to make a read-only entityset for Products. I am commenting out the line which creates the Edit link. This is from the ODataService sample.
ODataModelBuilder modelBuilder = new ODataModelBuilder();
var products = modelBuilder.EntitySet<Product>("Products");
//products.HasEditLink(entityContext => entityContext.UrlHelper.Link(ODataRouteNames.GetById, new { controller = "Products", id = entityContext.EntityInstance.ID }));
For the following request:
GET
http://kirandesktop:50231/Products(49)
I am seeing the following exception in the formatter write:
No EditLink factory was found. Try calling HasEditLink on the EntitySetConfiguration for 'Products'.
System.InvalidOperationException occurred
HResult=-2146233079
Message=No EditLink factory was found. Try calling HasEditLink on the EntitySetConfiguration for 'Products'.
Source=System.Web.Http.OData
StackTrace:
at System.Web.Http.OData.Builder.EntitySetLinkBuilderAnnotation.BuildEditLink(EntityInstanceContext context) in d:\Runtime\src\System.Web.Http.OData\OData\Builder\EntitySetLinkBuilderAnnotation.cs:line 88
InnerException:
Scenario2
- I am receiving errors for the following[1] Has<>Link actions…a scenario for HasEditLink is that, a user might want to show edit links only for specific instances, let’s say based on some criteria… I do not see much use case as to when a user would not want to generate an Feed link though…
- These[2] work fine…I do not see much use case as to when a user would not want to generate an Id link though…
-
For this[3], I am seeing that the links are still being generated…
static IEdmModel GetImplicitEdmModel()
{
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
var products = modelBuilder.EntitySet<Product>("Products");
modelBuilder.Entity<RatedProduct>().DerivesFrom<Product>();
var productFamilies = modelBuilder.EntitySet<ProductFamily>("ProductFamilies");
var suppliers = modelBuilder.EntitySet<Supplier>("Suppliers");
ActionConfiguration createProduct = modelBuilder.Entity<ProductFamily>().Action("CreateProduct");
createProduct.Parameter<string>("Name");
createProduct.Returns<int>();
var extendSupportDate = modelBuilder.Entity<Product>().TransientAction("ExtendSupportDate");
extendSupportDate.Parameter<DateTime>("newDate");
extendSupportDate.ReturnsCollectionFromEntitySet<Product>("Products");
[1]
extendSupportDate.HasActionLink(eic =>
{
return null;
});
products.HasIdLink(eic =>
{
return (string)null;
});
[2]
products.HasEditLink(eic =>
{
return (string)null;
});
products.HasFeedSelfLink(fc =>
{
return (string)null;
});
products.HasReadLink(eic =>
{
return (string)null;
});
[3]
products.HasNavigationPropertiesLink(
products.EntityType.NavigationProperties,
(entityContext, navigationProperty) =>
{
return null;
});