Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
简而言之,我该怎么做:
全选Departments连同其最新的 2 个 Staff。
Departments
Staff
我不需要所有的工作人员,只要 2 人。
注意:我需要启用延迟加载,以便在需要时仍然可以访问人员详细信息。
EF 不允许在预先加载时过滤/排序或限制导航属性上返回的记录数。您必须使用投影到匿名类型或自定义类型:
var data = from d in context.Departments select new { Department = d, Staffs = d.Staff.OrderBy(...).Take(2) };