Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AsEnumerable和AsQueryable在客户端WCF服务中应该使用哪一个_C#_Linq - Fatal编程技术网

C# AsEnumerable和AsQueryable在客户端WCF服务中应该使用哪一个

C# AsEnumerable和AsQueryable在客户端WCF服务中应该使用哪一个,c#,linq,C#,Linq,我有一个服务,它返回类型为List的数据 这个问题完全取决于服务调用,而不是数据库上下文 模型类是 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

我有一个服务,它返回类型为
List
的数据

这个问题完全取决于服务调用,而不是数据库上下文

模型类是

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; }
}
让我知道哪一个更适合客户?请解释这两种说法在操作上的区别


服务器返回一个列表。在客户端,这将转换为
列表
或数组。但是两者都已经实现了
IEnumerable
,所以答案是:两者都不实现。放下它

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

对于
AsQueryable()
的正确功能,您可以找到一个非常好的解释。基本上,正如您所知,您有一个内存中的集合,并且您的操作不需要
IQueryable
,在这里调用
AsQueryable()
对您没有任何帮助

服务器返回一个列表。在客户端,这将转换为
列表
或数组。但是两者都已经实现了
IEnumerable
,所以答案是:两者都不实现。放下它

var managers = client.GetDataMale().Where(m => m.Role == "Manager");
对于
AsQueryable()
的正确功能,您可以找到一个非常好的解释。基本上,正如您所知,您有一个内存中的集合,并且您的操作不需要
IQueryable
,在这里调用
AsQueryable()
对您没有任何帮助

如果在结果和where条件之间使用AsQueryable()。这意味着什么?如果是db,则表示它将创建SQL语法。但这是什么呢?如果我在结果和where条件之间使用AsQueryable(),请解释一下。这意味着什么?如果是db,则表示它将创建SQL语法。但这是什么呢?你能给我解释一下吗。。。
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");
}
    var bListEnum = client.GetDataMale().AsEnumerable().Where(m => m.Role == "Manager");
    var bListQuery = client.GetDataMale().AsQueryable().Where(m => m.Role == "Manager");
var managers = client.GetDataMale().Where(m => m.Role == "Manager");