我有LINQ结构的问题吗?
我将从Sharepoint自定义列表中获取所有列表项。如下所示
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,否则检查我的SearchKey单词是否在描述中?
select new
{
ProductName = ci["Component Name"].ToString(),
ID = ci.UniqueId.ToString(),
ItemID = ci.ID.ToString()
} ;
if( products > 0 )
{
//do somthing..
}
通过 vadivelu.B
答案 0 :(得分:0)
如果你真的给我们一个错误的解释,我们可以提供帮助。我确实看到这句话过于复杂而且与自己相矛盾......:
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())