none
Apply queries on custom class in OData.

    Pertanyaan

  • Hi,

        I am writing a new OData service and my controller looks like below.

    [EnableQuery]
        public class PeopleController : ODataController
        {
            public IHttpActionResult Get()
            {
               return Ok( DemoDataSources.Instance.People.AsQueryable());
            }
        }

    Everything works fine. Now my requirement is my response object will be wrapped with additional data as below.

       

     [EnableQuery]
        public class PeopleController : ODataController
        {
            public IHttpActionResult Get()
            {
                MyResult res = new MyResult();
                res.ConvId = "123";
                res.TransId = "123123";
                res.Result = DemoDataSources.Instance.People.AsQueryable();
                return Ok(res);
            }
        }
    
        public class MyResult
        {
            [Key]
            public string TransId { get; set; }
            public string ConvId { get; set; }
    
            public IQueryable<Person> Result { get; set; }
        }


    My webapiconfig.cs looks like below.

     private static IEdmModel GetEdmModel()
            {
                ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
                builder.Namespace = "Demos";
                builder.ContainerName = "DefaultContainer";
                builder.EntitySet<Person>("People");
                var edmModel = builder.GetEdmModel();
                return edmModel;
            }
     

    When I query using people, getting error "HTTP ERROR 406". 

    How to apply queries on Result property on my custom class (MyResult in above scenario)..

    Thanks,

    sanjay.


    • Diedit oleh msanjayv Senin, 07 Mei 2018 13.10 msg modified.
    • Dipindahkan oleh CoolDadTxMVP Senin, 07 Mei 2018 13.57 ASP.NET related
    Senin, 07 Mei 2018 13.05

Semua Balasan