var model = _db2.Persons.Select(
(x, index) => new
{
rn = index + 1,
col1 = x.Id
}).ToList();
错误:
LINQ to Entities不识别方法'System.Linq.IQueryable
1[<>f__AnonymousType2
2 [System.Int32,System.Int32]] Select[Person,<>f__AnonymousType22](System.Linq.IQueryable
1 [MvcApplication27.Models.Person], System.Linq.Expressions.Expression1[System.Func
3 [MvcApplication27.Models.Person,System.Int32,<>f__AnonymousType2`2 [System.Int32,System.Int32]]])',且该方法无法转换为存储表达式。
Persons
不是IQueryable
,先尝试使用Cast
或OfType
(如果它们存在的话)。 - King KingSystem.Linq.IQueryable
是返回类型,而不是方法名。你在方括号中看到的内容([<>f__AnonymousType22 [System.Int32,System.Int32]]
)是如果你手动输入它,会出现在<int, f__AnonymousType22<>>
中的内容。实际的函数在那个部分之后,即Select[Person,<>f_AnonymousType22](...)
。 - Scott Chamberlain