Reputation: 1557
I have the following class to store objects from a REST API call from SharePoint:
[Serializable]
public class DocumentSearchResult
{
public string TotalCount { get; set; }
public string DocumentPath { get; set; }
public string DocumentTitle { get; set; }
public string DocumentSize { get; set; }
public string DocumentAuthor { get; set; }
public string DocumentDescription { get; set; }
public string DocumentFileExtension { get; set; }
public double DocumentRank { get; set; }
public Int64 DocumentDocId { get; set; }
public Int64 DocumentWorkId { get; set; }
public DateTime DocumentWrite { get; set; }
public string DocumentParentLink { get; set; }
public DateTime DocumentLastModifiedDate { get; set; }
public string DocumentFileType { get; set; }
//These next set of properties are used for Viewing the results in embedded or preview
public string DocumentRedirectedEmbededURL { get; set; }
public string DocumentRedirectPreviewURL { get; set; }
public string DocumentRedirectURL { get; set; }
}
I create a list of these objects in my code:
var docReturnResult = new List<DocumentSearchResult>();
I have another list I create using:
var filterList = this.Where(x => x.TenantId == TenantId);
this will return an IQueryable list that contains a value I need to filter the second list. The filterList has an attribute called SharePointId (x => x.SharePointId) that I need to use to filter the docReturnResult list. So I need to compare the filterList SharePointId to the docReturnResult DocumentDocId and remove any objects in the docReturnResult list that don't match the SharePointId's in the filterList.
This is what I tried last:
var trimResults = new DocumentSearchResult();
trimResults = docReturnResult.RemoveAll(x => x.DocumentDocId != filterList.Where(y => y.SharePointId));
but I get an error:
Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type.
Any help is much appreciated.
Upvotes: 2
Views: 680
Reputation: 2607
Try this, it should remove all documents from docReturnResult
where match is not found in filterList
docReturnResult.RemoveAll(x => !filterList.Any(y => y.SharePointId == x.DocumentDocId));
Root cause of your error -
x.DocumentDocId != filterList.Where(y => y.SharePointId)
Right hand side will return IQuarable object and you are trying to compare it with DocumentDocId which will not work.
Edit
You don't need a new variable trmResults
, as RemoveALL on docReturnResult
will trim the same object, so you can just return docReturnResult
return docReturnResult.RemoveAll(x => !filterList.Any(y => y.SharePointId == x.DocumentDocId));
Upvotes: 2