0

I'm having a Service it returns the data of type List<Boss>.

This Question is Purely depends on Service Call, not a DB Context

The Model Classes are

public class Boss
{
    public int ID { get; set; }
    public int SID { get; set; }
    public string Name { get; set; }
    public string Department { get; set; }
    public string Gender { get; set; }
    public string Role { get; set; }
    public List<Person> Employees { get; set; }
}

public class Person
{
    public int ID { get; set; }
    public int SID { get; set; }
    public string Name { get; set; }
    public string Department { get; set; }
    public string Gender { get; set; }
    public string Role { get; set; }
    public List<PayrollInfo> PayInfo { get; set; }
}

public class PayrollInfo
{
    public int Monthof2015 { get; set; }
    public int NetWorkingDays { get; set; }
    public int AbsentDays { get; set; }
}

Just Imagine the Service

[OperationContract]
List<Boss> GetDataMale();

Outline of the Method should be

public List<Boss> GetDataMale()
{
    using(var db = new DBContext)
    {
        return db.Boss.Where(x => x.Gender == "Male").ToList();
    }
}

Now Consider the Client Side:

using(var client = new ServiceProvider())
{
    var bListEnum = client.GetDataMale().AsEnumerable().Where(m => m.Role == "Manager");
    var bListQuery = client.GetDataMale().AsQueryable().Where(m => m.Role == "Manager");
}

Let I know which one is preferable in Client ? Kindly explain the operational differentiation of these two statements.

    var bListEnum = client.GetDataMale().AsEnumerable().Where(m => m.Role == "Manager");
    var bListQuery = client.GetDataMale().AsQueryable().Where(m => m.Role == "Manager");

1 Answers1

3

Your server returns a list. On the client side this will be translated to either a List<> or an array. But both already implement IEnumerable<> so the answer is: neither. Just drop it.

var managers = client.GetDataMale().Where(m => m.Role == "Manager");

You can find a very nice explanation of what AsQueryable() does right here. Basically, as you know you have an in-memory collection and your operation does not need an IQueryable<>, calling AsQueryable() does nothing for you here.

Community
  • 1
  • 1
nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • If I used AsQueryable() in between the result and where condition. What it means ? If it is a db means it will create a SQL syntax. But here what it does? Can you please explain me please... –  Apr 20 '16 at 05:53