Hello there,
I installed the latest Microsoft.AspNet.WebApi.OData contribution and set up my project like proposed in this blog from Alex:
http://blogs.msdn.com/b/alexj/archive/2012/08/15/odata-support-in-asp-net-web-api.aspx
I made it to work so that I could query all or a specific object via a Controller.
But as soon as I try to use the ODataConventionModelBuilder to generate the $metadata for OData I get the following exception:
{
"message":"An error has occurred.",
"exceptionMessage":"Sequence contains more than one element",
"exceptionType":"System.InvalidOperationException",
"stackTrace":" at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.RemoveBaseTypeProperties(IEntityTypeConfiguration derivedEntity, IEntityTypeConfiguration baseEntity)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.DiscoverInheritanceRelationships()\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel()\r\n at System.Web.Http.HttpActionDescriptorExtensions.<>c__DisplayClass1.<GetEdmModel>b__0(Object _)\r\n at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)\r\n at System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(HttpActionDescriptor actionDescriptor, Type entityClrType)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"
}
The same exception occurs also when I try to use OData parameters like $top=50 or so.
Then I tried to use the ODataModelBuilder instead of the proposed convention builder.
This time I could at least access the Api again, but when I try to read the $metadata I get a "406 Not Acceptable" status code.
When i tried to debug into the issue i saw that this error happens in the "RemoveBaseTypeProperties" method while it tries to get the configuration2 for a "EntityReference<MyEntity>" class.
We use EntityFramework 5 with a database first approach with our Entities having various NavigationProperties to each other.
At least the second propblem with the 406 code also happens with the companion code sample linked in the mentioned blog.
With best regards,
Kay
I installed the latest Microsoft.AspNet.WebApi.OData contribution and set up my project like proposed in this blog from Alex:
http://blogs.msdn.com/b/alexj/archive/2012/08/15/odata-support-in-asp-net-web-api.aspx
I made it to work so that I could query all or a specific object via a Controller.
But as soon as I try to use the ODataConventionModelBuilder to generate the $metadata for OData I get the following exception:
{
"message":"An error has occurred.",
"exceptionMessage":"Sequence contains more than one element",
"exceptionType":"System.InvalidOperationException",
"stackTrace":" at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.RemoveBaseTypeProperties(IEntityTypeConfiguration derivedEntity, IEntityTypeConfiguration baseEntity)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.DiscoverInheritanceRelationships()\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel()\r\n at System.Web.Http.HttpActionDescriptorExtensions.<>c__DisplayClass1.<GetEdmModel>b__0(Object _)\r\n at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)\r\n at System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(HttpActionDescriptor actionDescriptor, Type entityClrType)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"
}
The same exception occurs also when I try to use OData parameters like $top=50 or so.
Then I tried to use the ODataModelBuilder instead of the proposed convention builder.
This time I could at least access the Api again, but when I try to read the $metadata I get a "406 Not Acceptable" status code.
When i tried to debug into the issue i saw that this error happens in the "RemoveBaseTypeProperties" method while it tries to get the configuration2 for a "EntityReference<MyEntity>" class.
We use EntityFramework 5 with a database first approach with our Entities having various NavigationProperties to each other.
At least the second propblem with the 406 code also happens with the companion code sample linked in the mentioned blog.
With best regards,
Kay