Web Api 2 With Entity Framework Controller return 所有导航属性

Web Api 2 With Entity Framework Controller return all navigation properties

我正在尝试使用用户 ID 从我的用户 table 获取信息,但我的控制器 return 是所有与外键连接到其他 table 的导航属性。

代码就是简单的webapi方法:

[ResponseType(typeof(User))]
    public IHttpActionResult GetUser(int id)
    {
        User user = db.User.Find(id);
        if (user == null)
        {
            return NotFound();
        }

        return Ok(user);
    }

不只是 return 用户,它 return 是与该用户相关的所有导航属性。

如何才能 return 只有用户?

This post 解释所选属性。我想要所有属性,但是控制器 return 也向我提供了所有连接的 tables 数据和外键。

Web-Applications 的最佳做法是禁用 DbContext 中的 LazyLoadin

context.Configuration.LazyLoadingEnabled = false;