检查属性在拉姆达前pression空 [英] Check if property is null in lambda expression

查看:129
本文介绍了检查属性在拉姆达前pression空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图绑定到一个列表视图对象的列表。我被两个属性排序。存在的问题,因此一些记录可能不具有的属性之一。这导致一个错误。我想它仍然绑定具有财产的记录。

 的IEnumerable< EREC>列表= retailerList.Cast< EREC>();
lvwRetailStores.DataSource = list.OrderByDescending(R =方式> r.Properties [RS_Partner类型]的ToString())
                                 .ThenBy(R =方式> r.Properties [RS_Title]的ToString());


解决方案

  list.Where(R = GT; r.Properties [RS_Partner_Type] = NULL&放大器;!&安培; R的.properties [RS_Title]!= NULL)
    .OrderByDescending(R =方式> r.Properties [RS_Partner类型]的ToString())
    .ThenBy(R =方式> r.Properties [RS_Title]的ToString());

或代替!= NULL,使用任何检测属性集合了。

I have a list of objects that I am trying to bind to a listview. I am sorting by two properties. The problem exists whereby some records may not have one of the properties. This is causing an error. I would like it to still bind the records that have the property.

IEnumerable<ERec> list = retailerList.Cast<ERec>();
lvwRetailStores.DataSource = list.OrderByDescending(r => r.Properties["RS_Partner Type"].ToString())
                                 .ThenBy(r => r.Properties["RS_Title"].ToString());

解决方案

list.Where(r => r.Properties["RS_Partner_Type"] != null && r.Properties["RS_Title"] != null)
    .OrderByDescending(r => r.Properties["RS_Partner Type"].ToString())
    .ThenBy(r => r.Properties["RS_Title"].ToString());

Or instead of != null, use whatever test the Properties collection has.

这篇关于检查属性在拉姆达前pression空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆