Tôi muốn chạy mã đơn giản LINQ này để có con số kỷ lục trong LINQ nhưng kết quả là dưới lỗiLINQ to Entities không nhận ra phương pháp 'System.Linq.IQueryable`
var model = _db2.Persons.Select(
(x, index) => new
{
rn = index + 1,
col1 = x.Id
}).ToList();
Lỗi:
LINQ to Entities does not recognize the method '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]]])' method, and this method cannot be translated into a store expression.
có vẻ như 'Người không phải là 'IQueryable', hãy thử sử dụng' Cast' hoặc 'OfType' (tất nhiên nếu chúng có mặt) trước tiên. –
Không, điều này là do chỉ mục để tìm số bản ghi. Đây là mã đầu tiên và tôi không có vấn đề gì khi tôi xóa chỉ mục trong lambda! – ehsan
Lưu ý tiêu đề 'System.Linq.IQueryable' là kiểu trả về chứ không phải tên phương thức. Những thứ bạn nhìn thấy trong dấu ngoặc vuông ('[<> f__AnonymousType22 [System.Int32, System.Int32]]') là những thứ có trong '>' nếu bạn gõ nó ra . Hàm thực tế là sau phần đó 'Chọn [Person, <> f_AnonymousType22] (...)'. –