none
Subquery RRS feed

  • Question

  • Is it possible to convert this to a Linq query, how?:

    SELECT     FullName,
            (SELECT     COUNT(*) 
           FROM          FormDocumentEmployee
           WHERE      (EmployeeId = Employee.EmployeePkId)) AS c
    FROM         Employee

    Thankx, Cheers Harry 

    Wednesday, August 10, 2011 3:33 PM

Answers

  • Hi Harry;

    The following Linq query should do what you need.

    var eNames = from emp in ObjectContext.Employees
           let count = (from fde in ObjectContext.FormDocumentEmployee
                 where fde.EmployeeId == emp.EmployeePkId
                 select fde).Count()
           select new {
             FullName = emp.FullName,
             Count = count
           }; 
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Harry Pfleger Thursday, August 11, 2011 8:08 AM
    Wednesday, August 10, 2011 7:29 PM

All replies

  • On 8/10/2011 11:33 AM, Harry Pfleger wrote:
    > Is it possible to convert this to a Linq query, how?:
    >
    > SELECT FullName,
    > *(SELECT COUNT(*) *
    > *FROM FormDocumentEmployee*
    > *WHERE (EmployeeId = Employee.EmployeePkId)) AS c
    > *FROM Employee
    >
     
    Look at the Aggregate operators...
     
     
     
    Wednesday, August 10, 2011 5:00 PM
  • Hi Harry;

    The following Linq query should do what you need.

    var eNames = from emp in ObjectContext.Employees
           let count = (from fde in ObjectContext.FormDocumentEmployee
                 where fde.EmployeeId == emp.EmployeePkId
                 select fde).Count()
           select new {
             FullName = emp.FullName,
             Count = count
           }; 
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Harry Pfleger Thursday, August 11, 2011 8:08 AM
    Wednesday, August 10, 2011 7:29 PM