VB.NET-LINQ to SQL-如何在VB.NET中将Row_Number添加到LINQ to SQL查询中? [英] VB.NET - LINQ to SQL - How do I add in Row_Number to a LINQ to SQL query in VB.NET?

查看:116
本文介绍了VB.NET-LINQ to SQL-如何在VB.NET中将Row_Number添加到LINQ to SQL查询中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加ROW_NUMBER到LINQ查询或实体?

如何将该解决方案转换为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查询中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆