【发布时间】:2010-01-25 20:59:16
【问题描述】:
我从名为 oProducts 的 Products 表中获取了一个实体框架对象集合。我正在遍历集合并从单独的函数中设置 Quantity 字段。在我用 HTML 写出对象的显示之前,我想按数量对它们进行排序。因此,我正在使用 LINQ 创建一个新集合并尝试从我刚刚修改的对象集合中进行排序。修改后的值肯定在对象集合中并正确输出,但排序顺序不适用于修改后的字段。有谁知道我忽略了什么或更好的尝试方法?
Dim oProducts = From p in ctx.Products _
Where p.Active = True _
Select p
For Each prod in oProducts
prod.Quantity = GetQuantity(prod.ProductID)
Next
Dim oOrderedProducts = From p in oProducts _
Order By p.Quantity Ascending _
Select p
For Each prod in oOrderedProducts
Response.Write(prod.Quantity.ToString())
'*** The Quantities are stored in the collection properly but it doesn't order by the Quantity field.
Next
【问题讨论】:
标签: vb.net linq entity-framework sql-order-by