简体   繁体   English

system.linq.IQueryable 不包含“To”的定义

[英]system.linq.IQueryable does not contain a definition for 'To'

I get an error in this code:我在此代码中收到错误消息:

this is the code:这是代码:

  public IHttpActionResult  Get()
    {
        var books = unit.Books.All;

        var response = books.To<BookDto>();

        return Ok(response);
    }

and right on books.To() I am getting this error:就在books.To()上,我收到了这个错误:

system.linq.IQueryable does not contain a definition for 'To' and system.linq.IQueryable 不包含“To”的定义和
extension method 'to' accepting a first argument of type 'system.linq.IQueryable' could be found.可以找到接受类型为“system.linq.IQueryable”的第一个参数的扩展方法“to”。 you you missing a using directive or an assembly reference?您是否缺少 using 指令或程序集引用?

I looked at this but no help.我看着这个,但没有帮助。

IQueryable<T> does not contain a definition for 'Include' and no extension method 'Include' IQueryable<T> 不包含“包含”的定义,也没有扩展方法“包含”

I have using System.Data.Entity;我有使用 System.Data.Entity; and also I have installed the EF from NuGet , but as the solution in the link I cant get the "QueryableExtensions" available in而且我已经从 NuGet 安装了 EF,但是作为链接中的解决方案,我无法获得“QueryableExtensions”

 using System.Data.Entity.QueryableExtensions

QueryableExtensions doesn't appear to contain any function named To , nor have I have ever heard of this method, so I suspect you're barking up the wrong tree in that regard. QueryableExtensions似乎不包含任何名为To函数,我也从未听说过这种方法,所以我怀疑您在这方面大错特错。

You likely need one of the following:您可能需要以下其中一项:

  1. var response = books.ToList(); for a List of books获取书籍列表

  2. var response = books.Cast<BookDto>(); to cast each objects in books to BookDtobooks每个对象投射到BookDto

  3. var response = books.Select(book => new BookDto(book)); to construct a sequence of BookDto objects from books , assuming there is a suitable constructor.假设有一个合适的构造函数,从books构造一系列BookDto对象。

IQueryable.To<T> isn't a thing. IQueryable.To<T>不是一回事。 If you're trying to convert to a different type, you'll likely need to use Select , eg.如果您尝试转换为其他类型,则可能需要使用Select ,例如。

var response = books.Select(book => new BookDto()); //Insert transformation logic into the new object initialization.

If you're trying to make a list, then simply do this:如果您想列出一个清单,那么只需执行以下操作:

var response = books.ToList();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ System.Linq.IQueryable”不包含“ GroupBy”的定义 - 'System.Linq.IQueryable' does not contain a definition for 'GroupBy' System.Linq.IQueryable不包含'Where'的定义 - System.Linq.IQueryable does not contain a definition for 'Where' “ System.Linq.IQueryable”不包含“ OrderByDescending”的定义 - 'System.Linq.IQueryable' does not contain a definition for 'OrderByDescending' “System.Linq.IQueryable <Sitecore.ContentSearch.SearchTypes.SearchResultItem> ”不包含“位置”的定义 - 'System.Linq.IQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>' does not contain a definition for 'Where' &#39;System.Linq.IQueryable <YuClone.Models.video> &#39;不包含&#39;添加&#39;的定义 - 'System.Linq.IQueryable<YuClone.Models.video>' does not contain a definition for 'Add' 模型不包含List的定义,并且找不到包含接受类型为system.linq.IQueryable的第一个参数的List的扩展方法 - Model does not contain a definition for List and no extension method List accepting a first argument of type system.linq.IQueryable) could be found LINQ to Entities 无法识别方法“System.Linq.IQueryable”1 - LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1 LINQ to Entities无法识别方法&#39;System.Linq.IQueryable` - LINQ to Entities does not recognize the method 'System.Linq.IQueryable` System.Linq.IQueryable错误 - System.Linq.IQueryable Error 无法序列化System.Linq.IQueryable接口 - Cannot serialize interface System.Linq.IQueryable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM