LINQ查詢結果分析
作者:佚名
這里介紹LINQ查詢結果,如果查詢結果是強類型的,如string[],List<T>等,就可以不用var類型,而是使用合適的 IEnumerable<T>或IEnumerable(因為IEnumerable<T>也擴展了IEnumerable)類型。
本文向大家介紹LINQ查詢結果,可能好多人還不了解LINQ查詢結果,沒有關系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。
使用LINQ查詢結果
如果查詢結果是強類型的,如string[],List<T>等,就可以不用var類型,而是使用合適的 IEnumerable<T>或IEnumerable(因為IEnumerable<T>也擴展了IEnumerable)類型。
- 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<string> 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)
- }
【編輯推薦】
責任編輯:佚名
來源:
IT168