locked
Count a customized query result RRS feed

  • Question

  • HI

    I'm newbie in silverlight. 

    I'd like to count the query result from the below coustomized query method. 

    How can I get the count of the query result without displaying the result on DataGrid?

    public IQeuryable<Employee> GetEmployees(string userID)

    {

         return this.ObjectContext.Emplyees.Where( e=> e.EmplyeeID == userID);

    }

    Monday, March 19, 2012 4:24 PM

Answers

  • Hi komunamu,

    Welcome to silverlight forum!

    In order to get the count of the query result, you can use the method Count.  And return null to not display the result on the DataGrid. Please modify it as follows:

    public IQeuryable<Employee> GetEmployees(string userID)
    {
        count = this.ObjectContext.Emplyees.Where( e=> e.EmplyeeID == userID).Count();
         return null;
    }
    

    Best wishes,

    Sunday, March 25, 2012 10:57 PM

All replies

  • Hi komunamu,

    Welcome to silverlight forum!

    In order to get the count of the query result, you can use the method Count.  And return null to not display the result on the DataGrid. Please modify it as follows:

    public IQeuryable<Employee> GetEmployees(string userID)
    {
        count = this.ObjectContext.Emplyees.Where( e=> e.EmplyeeID == userID).Count();
         return null;
    }
    

    Best wishes,

    Sunday, March 25, 2012 10:57 PM
  • How can I get the count of the query result without displaying the result on DataGrid?


    this method will return list of employees, if you already loaded the data in datagrid, then no need call domainservice again.

    you will have complete list with on client side and write linq on that and get the count.

    or else, write a new methd in domainservice which will return count of emplyees for given userid as Catherine Sh... suggested you.

    Monday, March 26, 2012 2:28 AM