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

后端 未结 5 754
野趣味
野趣味 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:47

    First: Turn Lazy Loading on.

    Second: If you want to filter down what you retrieve and return, then do a custom return object or something.

    from u in db.Users
    join r in db.Roles
      on u.RoleID equals r.RoleID
    select new { u.UserID, u.Title, u.Email, r.RoleName }
    

    Or something like that. You will have a minimal return object and your object graph will be tiny.

提交回复
热议问题