我想为一个独立的每个项目增加一个int属性(如here所述),因为引号需要像/person/quote/1..2..3
而不是/person/quote/1..5..10
一样可访问:< / p>
Quote Person Index
Lorem Smith 1
Ipsum Smith 2
Loremi Lewis 1
Ipsumi Lewis 2
在EF中使用该问题中的代码:
var query = _data.Quotes
.GroupBy(x => x.Person.Name)
.Select
(
x => x.Select((y, i) => new { y.Text, y.Person.Name, Index = i + 1 })
)
.SelectMany(x => x);
但EF无法解析它并返回NotSupportedException
异常:
LINQ to Entities does not recognize the method
System.Collections.Generic.IEnumerable`1[<>f__AnonymousType9`2[System.String,System.Int32]] Select[Quote,<>f__AnonymousType9`2](System.Collections.Generic.IEnumerable`1[App.Models.Quote], System.Func`3[App.Models.Quote,System.Int32,<>f__AnonymousType9`2[System.String,System.Int32]]) and this method cannot be translated into a store expression
答案 0 :(得分:2)
感谢 Dabblernl的评论,此代码正常运作:
var query = _data.Quotes
.GroupBy(x => x.Person.Name)
.ToList()
.Select
(
x => x.Select((y, i) => new { y.Person.Name, y.Text, Index = i + 1 })
)
.SelectMany(x => x);
答案 1 :(得分:0)
查询:
var query = _data.Quotes
.GroupBy(x => x.Person.Name.ToLower())
.Select
(
x => x.Select((y, i) => new { y.Text.ToLower(), y.Person.Name.ToLower(), Index = i + 1 })
)
.SelectMany(x => x);