有人会详细解释我在 SharePoint 项目上应用的这个 LINQ 查询吗?为什么使用 P 对象?
Will someone explain me this LINQ Query in Detail, which I have applied on SharePoint Project ? Why P object is used?
我想知道 P 在查询中做了什么,如果它是一个应该声明的对象,我就知道它是一个对象?我想知道的第二件事是 .cast SPListItem 在查询中做什么以及我们为什么需要它?
var dt = (from p in items.Cast<SPListItem>()
where (p["WorkflowName"] != null)
&& (Convert.ToString(p["WorkflowName"]).Split(',')[1].Trim() == "Approved")
select new
实际上我是 LINQ 的新手,想弄清楚我的概念 crystal。
LINQ 概念上 类似于 foreach
循环;这里的 p
只是代表 "for each item p
in items
, which we will assume is a SPListList
, apply some filter test (where
) on the properties of the item p
, and for those that match, apply some projection (select ...
)".
的一个记号
您可以也将其视为:
foreach(SPListItem p in items)
{
if (p["WorkflowName"] != null && ... )
{
var projection = new ...
// add/etc
}
}
然而,有一个重要的区别,因为 LINQ 通常是一个延迟查询,如有必要,可以由需要的代码检查和重写 - 例如,将 C# 转换为 SQL 对数据库执行。
我想知道 P 在查询中做了什么,如果它是一个应该声明的对象,我就知道它是一个对象?我想知道的第二件事是 .cast SPListItem 在查询中做什么以及我们为什么需要它?
var dt = (from p in items.Cast<SPListItem>()
where (p["WorkflowName"] != null)
&& (Convert.ToString(p["WorkflowName"]).Split(',')[1].Trim() == "Approved")
select new
实际上我是 LINQ 的新手,想弄清楚我的概念 crystal。
LINQ 概念上 类似于 foreach
循环;这里的 p
只是代表 "for each item p
in items
, which we will assume is a SPListList
, apply some filter test (where
) on the properties of the item p
, and for those that match, apply some projection (select ...
)".
您可以也将其视为:
foreach(SPListItem p in items)
{
if (p["WorkflowName"] != null && ... )
{
var projection = new ...
// add/etc
}
}
然而,有一个重要的区别,因为 LINQ 通常是一个延迟查询,如有必要,可以由需要的代码检查和重写 - 例如,将 C# 转换为 SQL 对数据库执行。