我正在使用数据库模式,其中记录在更新时不会被覆盖。而是添加记录的新副本并将其标记为“当前”。实体框架 - 急于使用过滤器加载?
例如:
Id | Current | Name | Owner
1 | false | Foo | Bar
1 | false | Foo | Bazz
1 | true | Foo | Buzz
在我的模型我有有许多与此相关的Post
个Blog
实体。每个Post
有许多与之相关的Comment
S:
public class Blog
{
public int Id {get; set};
public bool Current {get; set};
public ICollection<Post> Posts {get; set;}
}
public class Post
{
public int Id {get; set};
public bool Current {get; set};
public ICollection<Comment> Comments {get; set;}
}
public class Comment
{
public int Id {get; set};
public bool Current {get; set};
}
我想在this example from MSDN热切加载Blog
与所有Post
S和所有的Comment
小号很像:
using (var context = new BloggingContext()) { // Load all blogs, all related posts, and all related comments var blogs1 = context.Blogs .Include(b => b.Posts.Select(p => p.Comments)) .ToList(); }
但是,我想只包含数据库记录Current == true
。我如何用LINQ到EF来做到这一点?理想情况下,条件将进入JOIN
的ON
条款 - 这可能吗?
问题不是很清楚,大约.INCLUDE(B => b.Posts.Select(P => p.Comments.Where(注释=> comment.Current)))什么?? –
@ a-t谢谢。什么不清楚?您的建议不会扩展到博客和帖子,并给我:“包含路径表达式必须引用该类型上定义的导航属性。对引用导航属性使用虚线路径,对集合导航属性使用选择运算符。 – urig