我將如何返回一個唯一列表'listColl'我嘗試在'return listColl'的底部使用'Distinct9'''但收到一個錯誤,但它沒有奏效。目前這返回一個項目的重複列表,填充查詢中編碼的樹視圖。在asp-mvc4列表中返回不同的項目
public List<SPList> GetAllLibraries(string webURL)
{
var listColl = new List<SPList>();
ClientContext _ctx = new ClientContext(webURL);
try
{
var currentWeb = _ctx.Web;
var AllLists = currentWeb.Lists;
_ctx.Load(AllLists);
_ctx.ExecuteQuery();
var query = from list in currentWeb.Lists
where list.BaseType == BaseType.DocumentLibrary
select list;
var listCollection = _ctx.LoadQuery(query.Include(myList => myList.Title,
myList => myList.Id,
myList => myList.RootFolder.ServerRelativeUrl,
myList => myList.ParentWebUrl,
myList => myList.Hidden,
myList => myList.IsApplicationList));
_ctx.ExecuteQuery();
// /*
listColl.AddRange(from list in listCollection
where !list.Hidden
select new SPList
{
Title = list.Title,
ListGUID = list.Id.ToString(),
RootFolderServerRelativeUrl = list.RootFolder.ServerRelativeUrl,
ParentWebUrl = list.ParentWebUrl
});
// } */
foreach (var Item in listCollection)
{
listColl.Add(new SPList
{
Title = Item.Title,
RootFolderServerRelativeUrl = Item.RootFolder.ServerRelativeUrl,
ListGUID = Item.Id.ToString()
});
}
}
catch (Exception ex)
{
// error log
string error = ex.Message + " Error within GetAllLibraries ";
}
return listColl;
}
下面的答案沒有產生任何錯誤,他們也沒有解決這個問題。難道可能是Distinct的默認相等參數需要被覆蓋? – user3605501