Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq查询中的SPFieldLookupValue_Linq_Sharepoint - Fatal编程技术网

Linq查询中的SPFieldLookupValue

Linq查询中的SPFieldLookupValue,linq,sharepoint,Linq,Sharepoint,我正在尝试使用Linq和SPListItem的集合来计算SharePoint中查找字段的值,如下所示: int totalDepts = (from SPListItem itm in hourEntries select ((SPFieldLookupValue)itm["Level1"]).LookupValue).Distinct().Count(); 但这似乎不起作用(我觉得它遗漏了一些步骤) 以前有人这样做过吗?我无法在Linq查询中直接执行此操作,因此我最终创建了Workho

我正在尝试使用Linq和
SPListItem
的集合来计算SharePoint中查找字段的值,如下所示:

   int totalDepts = (from SPListItem itm in hourEntries select ((SPFieldLookupValue)itm["Level1"]).LookupValue).Distinct().Count();
但这似乎不起作用(我觉得它遗漏了一些步骤)


以前有人这样做过吗?

我无法在Linq查询中直接执行此操作,因此我最终创建了WorkhourEntries对象,并用我的所有SPListItems填充它

List<WorkHourEntry> workHourEntries = new List<WorkHourEntry>();
                foreach (SPListItem hourEntry in hourItems)
                {
                    //Collect entries that are in the current Fiscal Year reporting period
                    if (fiscalYearMonths.Contains(hourEntry["Reporting_x0020_Month"].ToString()))
                    {

                    WorkHourEntry curEntry = new WorkHourEntry();
                    string Level1 = (string)hourEntry["Level1"];
                    SPFieldLookupValue val = new SPFieldLookupValue(Level1);
                    curEntry.organization = val.LookupValue;
                    SPFieldCalculated cf = (SPFieldCalculated)hourEntry.Fields["WECSCHours"];
                    curEntry.WECSCHours = cf.GetFieldValueForEdit(hourEntry["WECSCHours"]);
                    workHourEntries.Add(curEntry);

                    }
                }

根据经验,Linq到SharePOint有点危险,而且很难定制。我的建议是创建纯CAML查询,如果语法有点复杂的话。最重要的是,使用CAML查询,您将确保您的查询将由Sharepoint处理,而不是在内存中。
var uniqueDeptNames = (from itm in workHourEntries select itm.organization).Distinct().ToArray();