Filtering navigation property in eager loading

▼魔方 西西 提交于 2019-12-06 01:35:31

Eager loading doesn't support filtering. Your code can be simplified to:

var users = Context.CreateSet<User>()
                   .Select(u => new {
                       User = u,
                       Salary = u.Salaries.Where(s => !s.Deleted)
                    })
                    .AsEnumerable()
                    .Select(a => a.User);

Include is not needed because you are replacing it with your own query and AsQueryable is not needed because the query is IQueryable all the time till called AsEnumerable which will sqitch to Linq-to-Objects when selecting users and selected salaries. EF will take care of correctly fixing navigation properties for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!