我無法弄清楚直接在LINQ查詢做到這一點,所以我結束了創建WorkHoursEntries對象,並且用我所有的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查詢填充它直接在WorkHourEntry集合
var uniqueDeptNames = (from itm in workHourEntries select itm.organization).Distinct().ToArray();
根據經驗,Linq to SharePOint有點危險,很難定製。我的建議是創建純CAML查詢,事件如果語法有點複雜。最重要的是,使用CAML查詢,您將確保您的查詢將由Sharepoint處理,而不是在內存中處理。 – 2014-09-04 13:17:13