我的读取与OData的语法数据: http://server.com/api/users $跳过= 20 & $顶部= 10的WebAPI控制器抛出“LINQ到实体无法识别方法”的错误
我想在我的Web API控制器中为每个获取的实体添加索引。 每当我收到以下错误:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable
1[WebPortal.Models.UserDto] Select[UserInDatabase,UserDto](System.Linq.IQueryable
1[DataContext.UserInDatabase], System.Linq.Expressions.Expression1[System.Func
3[DataContext.Media,System.Int32,WebPortal.Models.UserDto]])' method, and this method cannot be translated into a store expression.","ExceptionType":"System.NotSupportedException"
据我了解我无法使用选择(U,指数)=>选择实体框架环境中工作一段时间(正常工作在内存集合)。不幸的是,我用它通过的OData + QueryableAttribute暴露我的收藏:
public class UsersController : ApiController
{
[Queryable]
public IQueryable<UserDto> Get()
{
return _repository.Users
.Select((u, i) => new UserDto
{
Index = i,
Name = u.Name,
Age = u.Age
})
.AsQueryable();
}
}
我怎样才能修改取过程中继续使用OData的语法和具有与指数收益实体请求方的能力?
我的实体:
public class UserInDatabase
{
public string Name { get; set; }
public int Age { get; set; }
}
public class UserDto
{
public int Index { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
TIA
不幸的是,这不是这种情况,因为查询在应用过滤器之前从数据库中提取所有数据。我在那里有成千上万的行。这就是我引入分页的确切原因。 –
在* AsEnumerable()之前执行分页/过滤(跳过/取出)代码*。您的索引也必须考虑您跳过的行数(无论您跳过多少行,它将从0开始)。 –