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.
我有这段代码。
return Folder.GetAllWithInclude(x => x.SubFolder).Take(5);
此代码返回 5 个文件夹项。我想要做的是将子文件夹限制为 5,而不是将文件夹限制为 5。我尝试了以下
return Folder.GetAllWithInclude(x => x.SubFolder.Take(5));
但它似乎没有奏效。
我可能在这里遗漏了正确的语法。
非常感谢您!
没有办法Include(Where Expression)。如果您使用 Include,您将始终加载所有记录。
Include(Where Expression)
更新
你可以用Projection这个问题
Projection
Folder.Select(F => new { FolderName = F.FolderName, SubFolders = F.SubFolders.Take(5) }).ToList().Select(F => new Folder() { FolderName = F.FolderName, SubFolders = F.SubFolders };
code