首页 \ 问答 \ 如何使用lambda表达式和匿名类型获取类型的属性名称?(How do I get property names of a type using a lambda expression and anonymous type?)

如何使用lambda表达式和匿名类型获取类型的属性名称?(How do I get property names of a type using a lambda expression and anonymous type?)

我正在尝试使用表达式树和匿名类型来实现以下功能。

假设我有这个课程:

class Person
{
   public string FirstName {get;set;}
   public string MiddleName {get;set;}
   public string LastName {get;set;}
   public DateTime DateOfBirth {get;set;}
}

现在我希望能够调用以下内容:

string[] names = Foo<Person>(x=> new { x.LastName, x.DateOfBirth });

我希望名称包含2个项目,“LastName”和“DateOfBirth”。

我试图以编译时安全的方式扩展PetaPoco而不是编写字符串sql,这样我就可以指定我想要包含在SQL中的属性/列列表,而不是选择所有内容。 我有一些非常大的实体,有些情况下我不想出于性能原因选择所有列。


I am trying to use Expression Trees and anonymous types to achieve the following.

Let's say I have this class:

class Person
{
   public string FirstName {get;set;}
   public string MiddleName {get;set;}
   public string LastName {get;set;}
   public DateTime DateOfBirth {get;set;}
}

Now I want to be able to call the following:

string[] names = Foo<Person>(x=> new { x.LastName, x.DateOfBirth });

I want names to contain 2 items, "LastName" and "DateOfBirth".

I am trying to extend PetaPoco, in a compile time safe way rather than writing string sql, so that I can specify a list of properties/columns I want to include in the SQL, rather than it selecting everything. I have some pretty large entities and there are cases where I do not want to select all the columns for performance reasons.


原文:https://stackoverflow.com/questions/9916269
更新时间:2024-04-21 08:04

最满意答案

这将要求您在监视CPU的VM上运行服务。 然后,您需要使用自定义探针,指向超过200的情况下返回200以上的网页,以防超出cpu阈值。 您只是使用虚拟机(IaaS)还是云服务(PaaS)?


this will require you to have an service running on the VM that monitors the CPU. Then you need to use custom probes, point to a web page that return anything than 200 OK in case of cpu threshold exceeded. Are you just using Virtual machines (IaaS) or a cloud service (PaaS)?

相关问答

更多
  • 最简洁的答案是不。 Azure网站在内部查看整个服务器的运行状况,如果服务器不健康,则不会收到请求。 要提供更多详细信息,Azure网站负载均衡器使用加载索引来路由请求。 负载索引是根据工作服务器的资源负载计算的。 它还使用一些称为ARR亲和力cookie,使会话“粘滞”,即如果客户端正在为特定工作人员提供请求,则后续请求将由该工作人员提供。 请注意,可以使用IaaS(即Azure VM)配置显式路径以检查负载均衡器。 (来源:我是Azure Web Apps团队的开发人员) The short answe ...
  • 可用性集和流量管理器不是Azure中的相关主题。 在每个区域中创建两个虚拟机时,请确保将它们添加到同一个Cloud Service中。 这将实现负载平衡并在两个VM上实施可用性集行为。 在第二个区域重复此操作。 然后使用流量管理器使用故障转移策略(如果适用)将流量路由到云服务的公共接口。 虽然这是关于使用Web角色,但您可能会发现此博客系列很有用: http : //blog.kloud.com.au/2014/11/03/deploy-an-ultra-high-availablity-mvc-web-a ...
  • 通过以正确的方式配置端口解决了问题。 容器,服务和LB需要(显然)对齐。 我还添加了initialDelaySeconds 。 磅: apiVersion: extensions/v1beta1 kind: Ingress metadata: name: api namespace: production annotations: # kubernetes.io/ingress.allow-http: "false" kubernetes.io/tls-acme: "true" ...
  • 默认情况下,Azure VM位于Azure内部负载均衡器后面,该VM可以访问Internet,但您无法从Internet访问它。 如果要访问它,可以使用公共IP地址在该VM中创建VM,并将该VM用作跳转框。 您也可以为该VM分配公共IP地址,然后使用该公共IP地址访问该VM。 By default, Azure VM behind an Azure internal load balancer, that VM can access the internet, but you can't access it ...
  • Azure负载平衡器的公共和内部配置没有转发性能差异。 产品的基础是一样的。 而且,是的,流量将始终在微软的网络上传输。 公共配置和内部配置之间有一个重要区别:支持出站连接的SNAT。 只有公共Azure负载平衡器配置使SNAT可用。 这意味着游泳池中的一台机器可以到达与游泳池相关的公共VIP; 这不适用于内部Azure负载平衡器配置。 请务必查看了解出站连接以获取有关Azure中出站连接选项的详细信息。 Azure Load Balancer's public and internal configura ...
  • 我相信你正在寻找一个内部负载平衡器。 你可以在这里找到相关的文档: https : //docs.microsoft.com/en-us/azure/load-balancer/load-balancer-get-started-ilb-arm-portal 。 Azure内部负载平衡器(ILB)提供驻留在云服务内的虚拟机或具有区域范围的虚拟网络之间的网络负载平衡。 照常创建Load Balancer,但指定Type:Internal。 也许最好使它使用静态IP地址,所以它不会改变。 然后,您需要配置其后端 ...
  • 1)是否将负载均衡器放在这两个实例之前。 答案是肯定的 ,当你启用自动缩放设置后,当你的服务收到额外的流量时,你会得到更多的实例而不做任何事情。 2)这两台虚拟机是否会处于不同的故障域? 当部署多个Cloud Service角色实例时,Azure会将这些实例部署到不同的故障域。 有关云服务实例和故障域的更多信息,请参阅此blob 。 3)当我有两个实例,并从Visual Studio部署时,它是否将部署到两个实例? 不,在我们部署新软件包之后,它将应用于您的WebApp的所有实例。 有关如何将APP部署到A ...
  • 公共和内部Azure负载均衡器配置之间存在差异。 在公共负载平衡器配置中使用Azure负载均衡器时,SNAT用于出站请求。 这意味着公共后面的VM可以到达负载均衡器的公共IP地址,并且流量将相应地进行负载平衡。 这将为每个与VIP的连接消耗一个短暂的端口。 内部负载平衡器配置今天不提供SNAT。 反过来,内部负载平衡器配置不允许池成员访问内部负载平衡器的IP地址。 我们正在考虑在未来的版本中解决这个问题,允许选项为内部负载平衡器启用SNAT。 强制SNAT实际上可以为那些不需要访问负载均衡器的IP地址的人施 ...
  • 这将要求您在监视CPU的VM上运行服务。 然后,您需要使用自定义探针,指向超过200的情况下返回200以上的网页,以防超出cpu阈值。 您只是使用虚拟机(IaaS)还是云服务(PaaS)? this will require you to have an service running on the VM that monitors the CPU. Then you need to use custom probes, point to a web page that return anything th ...
  • 发现问题 - 需要NSG不仅允许AzureLoadBalancer,而且允许“Internet”命中端口80 / tcp。 应该早点考虑一下.. Found the issue - Needed the NSG to allow not just the AzureLoadBalancer, but "Internet" to hit port 80/tcp. Should have thought of that sooner..

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。