【问题标题】:How to query an entity's collection property asynchronously如何异步查询实体的集合属性
【发布时间】:2015-10-06 12:28:05
【问题描述】:

我的问题与异步查询 DbContext 子类的集合属性无关,而是与查询实体的集合属性有关。

假设我们遇到Async Query & Save (EF6 onwards) 给出的情况。

如果我们考虑类博客,它看起来像这样:

public class Blog 
{ 
    public int BlogId { get; set; } 
    public string Name { get; set; } 

    public virtual List<Post> Posts { get; set; } 
} 

如何异步查询 Posts 集合,例如:

await someBlog.Posts.Where(p => p.Title == ...).ToListAsync()

但问题是,ToListAsync() 不是 List 类的一部分,并且 System.Data.Entity 没有定义 ToListAsync() 扩展方法。

那么,如何异步查询集合属性呢?

【问题讨论】:

    标签: entity-framework entity-framework-6


    【解决方案1】:

    导航属性的异步加载is not supported in EF 6

    有一套解决方法here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      相关资源
      最近更新 更多