使用表达式在 EF4 中预加载多对多?
我有两个实体:GrmDeploymentAttempt
和 GrmDeploymentStep
。这些实体通过中间 POCO GrmDeploymentAttemptStep
建立多对多关系,其中包含有关实际多对多关系的附加信息。
我试图通过急切加载来加载所有步骤信息的尝试,所以现在我有以下代码:
var attempt = _context.GrmDeploymentAttempts
.Where(x => x.Id == attemptId)
.Include(x => x.AttemptSteps)
.FirstOrDefault();
问题是急切加载中间表,但不急切加载步骤表。如何将 Include()
与表达式一起使用来预先加载我的 Step
实体?使用 Include(string)
方法,我可以执行 Include("AttemptSteps.Steps")
但我不确定如何使用表达式执行此操作。
请注意,我知道我可以加载 AttemptSteps
实体并立即加载,但在某些情况下我无法执行此操作,并且我一直想知道如何处理此问题。
I have two Entities: GrmDeploymentAttempt
and GrmDeploymentStep
. These entities have a many to many relationship through an intermediary POCO GrmDeploymentAttemptStep
, which has additional information about the actual many-to-many relationship.
I am trying to load an attempt with all step information through eager loading, so right now I have the following code:
var attempt = _context.GrmDeploymentAttempts
.Where(x => x.Id == attemptId)
.Include(x => x.AttemptSteps)
.FirstOrDefault();
The problem is this eager load the intermediary table, but doesn't eager load the Steps table. How can I use the Include()
with expressions to eager load my Step
entity? Using the Include(string)
method I could do Include("AttemptSteps.Steps")
but I am not sure how to do this with expressions.
As a note, I know i could instead load the AttemptSteps
entity and eager load off of there, but there are some situations where I am unable to do this and I have been wondering how to handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Include(...Select(...))
通常会加载子集合的导航属性。Include(...Select(...))
generally loads a navigation property of a child collection.