[英]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:您可能需要以下其中一项:
var response = books.ToList();
for a List of books获取书籍列表
var response = books.Cast<BookDto>();
to cast each objects in books
to BookDto
将
books
每个对象投射到BookDto
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.