【问题标题】:How to use Entity Framework include with condition?如何使用实体框架包含条件?
【发布时间】:2014-06-24 15:14:45
【问题描述】:

假设我们有两个实体,PostsCommentsPosts 具有到 Comments 的导航属性,反之亦然:

public virtual ICollection<Comment> Comments { get; set; }

Comments 还具有 User 的导航属性:

public virtual User User { get; set; }

现在,如何查询所有帖子,仅包括最后一条评论(按评论创建日期)和创建该评论的用户?

【问题讨论】:

  • 显示你尝试过的代码
  • @Mak 加载所有包含所有 cmets 的帖子,包括用户,我们只需这样做:_db.Posts.Include(p => p.Comments.Select(p => p.User)).ToList() ;但由于性能问题,我只想要创建该评论的用户的最后一条评论。

标签: c# entity-framework


【解决方案1】:

当前版本的 EF 不可能,但您可以在这里投票 https://entityframework.codeplex.com/workitem/47

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 2022-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    相关资源
    最近更新 更多