简体   繁体   English

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

[英]AsEnumerable and AsQueryable which one should be used in Client - WCF Service

I'm having a Service it returns the data of type List<Boss> . 我有一个服务,它返回类型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"); 

Your server returns a list. 您的服务器返回一个列表。 On the client side this will be translated to either a List<> or an array. 在客户端,这将被转换为List<>或数组。 But both already implement IEnumerable<> so the answer is: neither . 但是两者都已经实现了IEnumerable<>因此答案是: 都没有 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 . 您可以在此处找到关于AsQueryable()很好的解释。 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. 基本上,您知道您有一个内存中的集合,并且您的操作不需要IQueryable<> ,在这里调用AsQueryable()不会为您做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 链接AsEnumerable和AsQueryable是否安全? - Is it safe to chain AsEnumerable and AsQueryable? Java客户端使用的WCF服务和WCF客户端使用的Java服务 - WCF Service used by Java client and Java Service used by WCF client 有人用SSCF作为Web服务的WCF客户端吗? - Anyone used a WCF client with SSRS a web service? WCF服务安全性-多台服务器,一个客户端 - WCF service security - many servers, one client 为什么.ToList()和AsEnumerable()使我的查询区分大小写,而AsQueryable()不区分大小写? - Why are .ToList() and AsEnumerable() making my query case sensitive but AsQueryable() is not? .net 核心 6 - 实体框架 - 何时使用 AsEnumerable AsQueryable - .net core 6 - Entity Framework - when to use AsEnumerable AsQueryable 温莎WCF客户端可以在配置为单例的服务中使用吗? - Can a Windsor WCF client be used in a service configured as singleton? 自定义端点行为未在具有服务引用的WCF客户端中使用 - Custom Endpoint Behavior not being used in WCF Client with Service Reference 使用WCF服务从一个客户端到另一客户端的文件传输 - File Transfer using WCF Service from One Client To Another Client 仅为WCF服务上可用的服务合同接口之一生成客户端 - Generate client for only one of the Service Contract interfaces available on a WCF service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM