开发者

Checking if list item is empty with LINQ at where condition?

i have a problem with LINQ structure ?

i will fetch the all the list item from Sharepoint customlist.. like following

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)  

Here I want to check whether the component description is null, if true return null/false ,otherwise check whether my SearchKey word in description ?

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


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

by vadivelu.B


If you actually give us an explanation of what is wrong we can help. I did see that this statement is overly complex and contradicts itself..:

 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)  

Assuming you want items that have a name or description, it reduces to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜