问题描述
如何将该解决方案转换为VB.NET?
How can I convert this solution to VB.NET?
var start = page * rowsPerPage;
Products.OrderByDescending(u => u.Sales.Count())
.Skip(start)
.Take(rowsPerPage)
.AsEnumerable()
.Select((u, index) => new { Product = u, Index = index + start }); // this line gets me
我在移植最后一行时遇到了麻烦.我一直找不到VB.NET示例.
I'm having trouble porting that last line. I have been unable to locate a VB.NET example.
我实际上并没有在寻找该示例所提供的任何分页功能,只是好的老式Row_Number(Order By X)
行索引.
I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X)
row index.
推荐答案
LinqToSql无法在数据库中执行Row_Number(按X排序).
LinqToSql can't do a Row_Number(Order By X) in the database.
您发布的C#代码通过调用Enumerable.Select对内存中的实例进行了
The c# code you posted does it against in-memory instances by calling Enumerable.Select
在 msdn页面上进行Enumerable.Select,有一个vb .net示例.
On the msdn page for Enumerable.Select, there's a vb.net example.
以下是一个有效的示例,演示了VB.NET中行索引的投影:
Dim R = (
From P In DB.Products Select P
).AsEnumerable().Select(
Function(Product, index) New With {index, Product}
)
Response.Write(R(12).Product.Doc_width.ToString()) 'Access object members
Response.Write(R(12).index.ToString() 'Access Row Index
这篇关于VB.NET-LINQ to SQL-如何在VB.NET中将Row_Number添加到LINQ to SQL查询中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!