很多人还不是很了解Linq查询结果,为了解决大家的这个盲区,笔者写了一篇关于内容的文章,当你看完本文一定会收获很大的。
使用Linq查询结果:
如果查询结果是强类型的,如string[],List
- class Program
- {
- static void Main(string[] args)
- { Console.WriteLine("***** LINQ Transformations *****"n");
- IEnumerable<string> subset = GetStringSubset();
- foreach (string item in subset)
- {
- Console.WriteLine(item);
- }
- Console.ReadLine();
- }
- static IEnumerable<string> GetStringSubset()
- {
- string[] currentVideoGames = {"Morrowind", "BioShock",
- "Half Life 2: Episode 1", "The Darkness",
- "Daxter", "System Shock 2"};
- // Note subset is an IEnumerable
compatible object. - IEnumerable<string> subset = from g in currentVideoGames
- where g.Length > 6
- orderby g
- select g;
- return subset;
- }
- }
使用Linq查询结果的分页处理:
- var custTotalOrders = from c in db.D_WorkCenter
- //join o in db.Orders
- //on c.CustomerID equals o.CustomerID into custOrders
- //from o in custOrders select new
- {
- WorkCenterID = c.WorkCenterID,
- WorkCenterName = c.WorkCenterName
- //OrderTotal = o.Order_Details.Sum(d => d.UnitPrice * d.Quantity)
- }
以上就是对Linq查询结果的简单分析。
【编辑推荐】