请看MSDN为例http://msdn.microsoft.com/en-GB/library/bb155995.aspx
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
string queryString =
@"SELECT VALUE product FROM AdventureWorksEntities.Products AS product";
ObjectQuery<Product> productQuery1 =
new ObjectQuery<Product>(queryString, context, MergeOption.NoTracking);
ObjectQuery<Product> productQuery2 = productQuery1.Top("2");
// Iterate through the collection of Product items.
foreach (Product result in productQuery2)
Console.WriteLine("{0}", result.Name);
}
或者,如果你只是有List<T>
考虑使用Take()
扩展名。
List<string> strs = new List<strs>() { "1", "2", "3", "4" };
var firstTwo = strs.Take(2);
http://msdn.microsoft.com/ru-ru/library/bb300906.aspx – 2kay 2013-04-22 08:14:49