在where条件下使用LINQ检查列表项是否为空?

在where条件下使用LINQ检查列表项是否为空?,linq,Linq,我对LINQ结构有问题吗 我将从Sharepoint customlist获取所有列表项。。像下面 SPList ComponentMaster = Site.Lists[Constants.Lst_CompMaster]; var products = from SPListItem ci in ComponentMaster .Items where ci["Component Name"].ToString().Contains(SearchKey) |

我对LINQ结构有问题吗

我将从Sharepoint customlist获取所有列表项。。像下面

SPList ComponentMaster = Site.Lists[Constants.Lst_CompMaster];

 var products = from SPListItem ci in ComponentMaster .Items
                where ci["Component Name"].ToString().Contains(SearchKey) ||
                      (
                         ( ci["Component Description"] == null &&           
                           !string.IsNullOrEmpty(
                               ci["Component Description"].ToString()
                            )
                       ) ? true:false)  
这里我想检查组件描述是否为null,如果为true,则返回null/false,否则检查我的searchkeyword是否在描述中

select new
{
    ProductName = ci["Component Name"].ToString(),
    ID = ci.UniqueId.ToString(),
    ItemID = ci.ID.ToString()                                             
} ;


if( products > 0 )
{
    //do somthing..
}

vadivelu.B

如果你真的给我们解释一下什么是错的,我们可以帮你。我确实看到这句话过于复杂,自相矛盾

 var products = from SPListItem ci in ComponentMaster .Items
            where ci["Component Name"].ToString().Contains(SearchKey) ||
                  (
                     ( ci["Component Description"] == null &&           
                       !string.IsNullOrEmpty(
                           ci["Component Description"].ToString()
                        )
                   ) ? true:false)  
假设您需要具有名称或说明的项目,则其减少为:

 var products = from SPListItem ci in ComponentMaster .Items
            where ci["Component Name"].ToString().Contains(SearchKey) ||   
                  string.IsNullOrEmpty(ci["Component Description"].ToString())

我支持,@user801463如果你想让人们努力回答你的问题,请努力让他们清楚地知道你在问什么!现在我们已经更正了您的代码,您的问题是什么?