【问题标题】:can not reference ToListAsync() inside my asp.net mvc4 + entity framework 5无法在我的 asp.net mvc4 + 实体框架 5 中引用 ToListAsync()
【发布时间】:2015-09-04 16:10:37
【问题描述】:

我正在开发一个 asp.net mvc4 web 应用程序 + 实体框架 5。我试图引用 ToListAsync() 如下:-

var tservers = await t.TServers.Include(a => a.Technology.TechnologyIPs).Include(a => a.TVirtualMachines.Select(a2 => a2.Technology))
                   .Where(
           a2 => (!singlescan && String.IsNullOrEmpty(FQDN) && a2.TechnologyRole.Name.ToLower() == "hypervisor")
                 ||
                 (singlescan && !String.IsNullOrEmpty(FQDN) && a2.Technology.IT360ID == it360id)
                   ).ToListAsync();

但我不断收到以下错误:-

Error   10  'System.Linq.IQueryable<**.Models.**>' does not contain a definition for 'ToListAsync' and no extension method 'ToListAsync' accepting a first argument of type 'System.Linq.IQueryable<**.Models.***>' could be found (are you missing a using directive or an assembly reference?)    C****\Repository.cs 181 22   Scanning

我将这些参考资料包含在我的班级中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data;
using System.Data.Objects.SqlClient;
using System.Data.Entity.Infrastructure;
using T.ViewModels;
using System.DirectoryServices.AccountManagement;
using System.Security.Principal;
using System.DirectoryServices;
using System.Linq.Expressions;
using System.Data.Objects;
using System.Linq.Dynamic;
using System.Configuration;
using System.Threading.Tasks;

究竟是什么问题? ToListAsync() 在 EF 5 中可用吗?

【问题讨论】:

    标签: asp.net-mvc entity-framework asp.net-mvc-4 entity-framework-5


    【解决方案1】:

    没有。它不是。它是在 EF6 中添加的。

    【讨论】:

    • 同样适用于 SaveChangesAsync() 吗?
    • 是的。所有的异步 EF 函数都是在 6 中引入的。以前它只是同步的。虽然,EF 还没有更进一步,实际上允许真正的异步同时查询,所以每个查询都是异步处理的,但是多个查询仍然必须串行运行。
    • 但在 EF 5 中我可以使用一些 Async 方法,例如 DownloadStringTaskAsync 和 DownloadStringAsync ,所以似乎某些 Async 方法在 EF 5 中可用?这是正确的吗?
    • 那些不是 EF 方法。是的,ASP.NET 的其他领域已经有一段时间支持异步了。但是,EF 直到版本 6 才获得异步支持。
    猜你喜欢
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2021-01-08
    • 1970-01-01
    相关资源
    最近更新 更多