我想有一個遞增的獨立組各項目(如描述here一個int屬性,因爲報價所需的可訪問樣/person/quote/1..2..3
不/person/quote/1..5..10
:實體框架遞增的索引屬性組
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
添加'.ToLower()'每串查詢並再次運行 – Ani
只檢索通過在查詢中插入一個.ToList到Linq to Entities仍然可以理解的位置來分組數據。在此之後,你在LINQ to Objects並可以應用索引。 – Dabblernl