Entity Framework always includes data that is in context even if I don't ask for it

后端 未结 5 757
野趣味
野趣味 2021-02-07 02:18

I am using MVC.NET web api, EF with DB first, and I have lazy loading turned off on my context. EF is returning way too much data, even with LazyLoading turned off.

For

5条回答
  •  被撕碎了的回忆
    2021-02-07 02:59

    You can select only what you need by using Select().

    var users = _db.Users.Select(x => new
    {
        UserID = x.UserID,
        Title = x.Title,
        Email = x.Email,
        RoleID = x.RoleID
    }).AsEnumerable();
    

提交回复
热议问题