2010-07-12 20 views

回答

1

亚音速总是有一个“后门”。这就是所谓的InlineQuery(亚音速2.2)或CodingHorror(亚音速3):http://subsonicproject.com/docs/CodingHorror

您的SQL查询可能会是这样的:

SELECT top 3 
newid() as sortorder, id 
FROM some_table 
ORDER by sortorder 

所以我建议这样的事情

List<int> result = new CodingHorror(@" 
     SELECT TOP 3 
     id, newid() as sortorder 
     FROM some_table 
     ORDER by sortorder 
    ).ExecuteTypedList<int>(); 

如果它没有从subsonic 2.2更改为3,ExcecuteTypedList()方法在与valueType一起使用时返回查询中的第一个元素作为泛型类型参数。在这种情况下:id。

这可能会实现,也:

List<Product> result = new CodingHorror(@" 
     SELECT TOP 3 
     *, newid() as sortorder 
     FROM products 
     ORDER by sortorder 
    ).ExecuteTypedList<Product>();