For example, I want to change the navigation property link by providing my own link builder code:
public class Todo
{
public int Id { get; set; }
public Person CreatedBy { get; set; }
}
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
}
var builder = new ODataConventionModelBuilder();
var todoes = builder.EntitySet<Todo>("Todo");
todoes.HasNavigationPropertiesLink(
todoes.EntityType.NavigationProperties,
(entityContext, navigationProperty) => new Uri(entityContext.UrlHelper.Link(ODataRouteNames.PropertyNavigation, new { Controller = "Todo", parentId = entityContext.EntityInstance.Id, NavigationProperty = navigationProperty.Name })));
return builder.GetEdmModel();
The code reports following error:
System.InvalidOperationException occurred
HResult=-2146233079
Message=No NavigationLink factory was found for the property 'CreatedBy' on entity set 'Todo'. Try calling HasNavigationPropertyLink on the EntitySetConfiguration.
Source=System.Web.Http.OData
StackTrace:
at System.Web.Http.OData.Builder.EntitySetLinkBuilderAnnotation.BuildNavigationLink(EntityInstanceContext context, IEdmNavigationProperty navigationProperty) in C:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\runtime\src\System.Web.Http.OData\OData\Builder\EntitySetLinkBuilderAnnotation.cs:line 121
InnerException:
Comments: Introduce an extensibility point to allow user to modify the model before finally building the model.
public class Todo
{
public int Id { get; set; }
public Person CreatedBy { get; set; }
}
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
}
var builder = new ODataConventionModelBuilder();
var todoes = builder.EntitySet<Todo>("Todo");
todoes.HasNavigationPropertiesLink(
todoes.EntityType.NavigationProperties,
(entityContext, navigationProperty) => new Uri(entityContext.UrlHelper.Link(ODataRouteNames.PropertyNavigation, new { Controller = "Todo", parentId = entityContext.EntityInstance.Id, NavigationProperty = navigationProperty.Name })));
return builder.GetEdmModel();
The code reports following error:
System.InvalidOperationException occurred
HResult=-2146233079
Message=No NavigationLink factory was found for the property 'CreatedBy' on entity set 'Todo'. Try calling HasNavigationPropertyLink on the EntitySetConfiguration.
Source=System.Web.Http.OData
StackTrace:
at System.Web.Http.OData.Builder.EntitySetLinkBuilderAnnotation.BuildNavigationLink(EntityInstanceContext context, IEdmNavigationProperty navigationProperty) in C:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\runtime\src\System.Web.Http.OData\OData\Builder\EntitySetLinkBuilderAnnotation.cs:line 121
InnerException:
Comments: Introduce an extensibility point to allow user to modify the model before finally building the model.