(în curs de editare)

PASUL 1 . Modificare DAL pentru a folosi LINQ

using System.Linq;

using System.Collections.Generic;
using AdventureWorksModel;


namespace WebApplication3
{
    public class CustomerDataSource
    {
        public static List<Customer> GetCustomers() { 
           using (AdventureWorksLTModel aw = new AdventureWorksLTModel() )
           {
               return GetQuery(aw).OrderBy(c => c.CompanyName).Skip(10).Take(5).ToList();
           }
        }


        public static IQueryable<Customer> GetQuery(AdventureWorksLTModel aw)
        { 
           var query = from c in aw.Customer
                       where c.SalesOrderHeaderes.Sum(s=> s.TotalDue) > 5000
                       select c;

           return query;
        }
    }
}

PASUL 2 . Verificare în SQL Profiler

 

SELECT TOP (5) 
[Filter2].[CustomerID] AS [CustomerID], 
[Filter2].[Title] AS [Title], 
[Filter2].[FirstName] AS [FirstName], 
[Filter2].[MiddleName] AS [MiddleName], 
[Filter2].[LastName] AS [LastName], 
[Filter2].[Suffix] AS [Suffix], 
[Filter2].[CompanyName] AS [CompanyName], 
[Filter2].[SalesPerson] AS [SalesPerson], 
[Filter2].[EmailAddress] AS [EmailAddress], 
[Filter2].[Phone] AS [Phone]
FROM ( SELECT [Project2].[CustomerID] AS [CustomerID], 
[Project2].[EmailAddress] AS [EmailAddress],
[Project2].[Phone] AS [Phone],
[Project2].[Title] AS [Title],
[Project2].[FirstName] AS [FirstName],
[Project2].[MiddleName] AS [MiddleName],
[Project2].[LastName] AS [LastName],
[Project2].[Suffix] AS [Suffix],
[Project2].[CompanyName] AS [CompanyName],
[Project2].[SalesPerson] AS [SalesPerson],
[Project2].[C1] AS [C1],
row_number() OVER (ORDER BY [Project2].[CompanyName] ASC) AS [row_number]     FROM ( SELECT         [Extent1].[CustomerID] AS [CustomerID],         [Extent1].[EmailAddress] AS [EmailAddress],         [Extent1].[Phone] AS [Phone],         [Extent2].[Title] AS [Title],         [Extent2].[FirstName] AS [FirstName],         [Extent2].[MiddleName] AS [MiddleName],         [Extent2].[LastName] AS [LastName],         [Extent2].[Suffix] AS [Suffix],         [Extent2].[CompanyName] AS [CompanyName],         [Extent2].[SalesPerson] AS [SalesPerson],         (SELECT             SUM([Project1].[TotalDue]) AS [A1]             FROM ( SELECT                 [Extent3].[TotalDue] AS [TotalDue]                 FROM [dbo].[SalesOrderHeader] AS [Extent3]                 WHERE [Extent1].[CustomerID] = [Extent3].[CustomerID]             ) AS [Project1]) AS [C1]         FROM [dbo].[CustomerContactInfo] AS [Extent1]         INNER JOIN [dbo].[Customer] AS [Extent2] ON [Extent1].[CustomerID] = [Extent2].[CustomerID]     ) AS [Project2]     WHERE [Project2].[C1] > cast(5000 as decimal(18)) ) AS [Filter2] WHERE [Filter2].[row_number] > 10 ORDER BY [Filter2].[CompanyName] ASC

 

 

 
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview