locked
OData Controller returns 406 for types in dynamically generated assemblies RRS feed

  • Question

  • User872667305 posted

    Hi,

    Thanks in advance.

    I am trying to create a type with System.Reflection.Emit and set up the model by calling something like following:

    typeof(ODataConventionModelBuilder).GetMethod("EntitySet").MakeGenericMethod(t).Invoke(modelBuilder, new object[] { typename + "s" });

    And metadata returns correctly. However, when I try to query the data with a generic controller:

    public IQueryable Get()
    {
        ODataPath path = Request.ODataProperties().Path;
        IEdmCollectionType collectionType = (IEdmCollectionType)path.EdmType;
        IEdmEntityTypeReference entityType = collectionType.ElementType.AsEntity();
        return DynamicEDMBuilder.Instance.Get(entityType).AsQueryable();
    }

    It returns 406 status code.

    Any  idea how I can rectify this issue?

    Thanks

    Thursday, April 30, 2015 3:03 PM

All replies

  • User1644755831 posted

    Hello Fardream1,

    1. To enable OData query options globally, call EnableQuerySupport on the HttpConfiguration class at startup. Have you done this? The EnableQuerySupport method enables query options globally for any controller action that returns an IQueryable type. If you don’t want query options enabled for the entire application, you can enable them for specific controller actions by adding the [Queryable] attribute to the action method.

    You can follow this article to understand more.

    Supporting OData Query Options in ASP.NET Web API 2

    Hope this helps.

    With Regards,

    Krunal Parekh

    Monday, May 4, 2015 10:36 PM
  • User872667305 posted

    Hi, Krunal,

    Thanks for the reply but I don't think you are answering my question. I am asking that how to add support to classes that is generated on the fly.

    Friday, May 15, 2015 10:04 AM
  • User1644755831 posted

    Hello Fardream1,

    For this you could try posting this question at github odata issues https://github.com/OData/odata.net/issues. you are likely to get more response from there.

    With Regards,
    Krunal Parekh

    Sunday, May 17, 2015 10:17 PM