1

Closed

NRE when defining navigation property in derived type by explicit model builder

description

Repro code is attached.
Send request: GET http://localhost:50232/vehicles to repro the issue The exception is: System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=System.Web.Http.OData
StackTrace:
   at System.Web.Http.OData.Builder.EntitySetLinkBuilderAnnotation.BuildNavigationLink(EntityInstanceContext context, IEdmNavigationProperty navigationProperty) in d:\git\WebStackRuntime\src\System.Web.Http.OData\OData\Builder\EntitySetLinkBuilderAnnotation.cs:line 124
InnerException:

The problem here is that when navigation property is added to derived type, model builder will try to add the same navigation property to it's base type. Because I didn't set HasNavigationPropertiesLink on base type, it will throw NRE. The solution here is to call HasNavigationPropertiesLink for all navigation properties from derived and base types. It is a good experience to me. Can we copy those navigation properties automatically?

file attachments

Closed Jan 18 at 9:44 PM by hongyes
Verified

comments

HongmeiG wrote Oct 18, 2012 at 10:02 PM

We should give a better exception in this case.