WebAPI and ODataController return 406 Not Acceptable

前端 未结 13 1322
余生分开走
余生分开走 2020-12-02 12:25

Before adding OData to my project, my routes where set up like this:

       config.Routes.MapHttpRoute(
            name: \"ApiById\",
            routeTempl         


        
13条回答
  •  广开言路
    2020-12-02 12:56

    For me the problem was, that I used LINQ and selected the loaded objects directly. I had to use select new for it to work:

    return Ok(from u in db.Users
              where u.UserId == key
              select new User
              {
                  UserId = u.UserId,
                  Name = u.Name
              });
    

    This did not work:

    return Ok(from u in db.Users
              where u.UserId == key
              select u);
    

提交回复
热议问题