简体   繁体   English

C# 实体框架分页子项包括

[英]C# Entity Framework Pagination Children Includes

I am looking for the fastest way to do the following operation.我正在寻找执行以下操作的最快方法。 What I need to accomplish, is I have a screen that displays the "Parts" that are defined inside of a "Lot".我需要完成的是,我有一个屏幕显示在“批次”内定义的“零件”。 Each part has objects of a station, and each station has objects of tools, and each tool can have measurements.每个零件都有一个站的对象,每个站都有工具的对象,每个工具都可以有测量值。

My problem is I cannot get the pagination to work.我的问题是我无法让分页工作。 The incoming offset is 0, and the number of records to take is 20 however the following operation is not working:传入的偏移量为 0,要获取的记录数为 20,但是以下操作不起作用:

Lot foundLot = EntitiesContext.Lots.Where(x => x.ID == lotID).IncludeFilter(lot => lot.Parts.OrderBy(n => n.PartID).Skip(offset).Take(numberOfRecords).ToList()).IncludeOptimized(lot => lot.Parts.Select(parts => parts.Stations)).IncludeOptimized(lot => lot.Parts.Select(parts => parts.Stations.Select(station => station.Tools))).IncludeOptimized(lot => lot.Parts.Select(parts => parts.Stations.Select(station => station.Tools.Select(tools => tools.Measurements)))).FirstOrDefault();

So I am trying to filter to only grab certain parts, and then of those filtered parts, I want to grab all of the children's data associated with them.所以我试图过滤以只抓取某些部分,然后在那些过滤的部分中,我想抓取与它们相关联的所有孩子的数据。 I have checked all of the existing stack overflow articles related to this, and the changes I make either result in the Z.EntityFrameworkPlus package throwing a generic exception, that provides no details (which is what the above code does), or if I use the regular EntityFramework functions it throws an exception for the invalid path.我已经检查了与此相关的所有现有堆栈溢出文章,并且我所做的更改会导致 Z.EntityFrameworkPlus package 抛出一个通用异常,该异常没有提供任何细节(上面的代码就是这样做的),或者如果我使用常规的 EntityFramework 函数会为无效路径引发异常。

Thank you for your assistance.谢谢您的帮助。

Okay, after reading the docs for Z.EntityFrameworkPlus I now see you cannot use IncludeFilter and IncludeOptimzed on the same LINQ statement好的,在阅读了 Z.EntityFrameworkPlus 的文档后,我现在看到您不能在同一个 LINQ 语句上使用 IncludeFilter 和 IncludeOptimzed

https://entityframework-plus.net/query-include-optimized https://entityframework-plus.net/query-include-optimized

I switched IncludeFilter to IncludeOptimzed and it works.我将 IncludeFilter 切换到 IncludeOptimzed 并且它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM