I decided I would use LINQ to build the collection to bind to my ListView. Doing such, would allow me to move all the string parsing out of the front-end and into my classes. The only problem is that SharePoint collections are not queryable. A quick Google search, took me to a blog post by Asfar Sadewa, Direct Linq to SPListItemCollection. Then I thought, why not make this generic so that it can be applied to all SharePoint collections? Below is the result:
public class QueryableSharePointCollection<C, T> : List<T> where C : SPBaseCollection
{
public QueryableSharePointCollection(C sharepointCollection)
{
this.Clear();
foreach (T item in sharepointCollection)
{
this.Add(item);
}
}
}
Now I just have to instantiate a new QueryableSharePointCollection, specifying the collection type, and the type of the items in the collection, and I have a queryable collection derived from a SharePoint collection.
Nice! In sharepoint 2010 you can also code gen your classes for querying lists using spmetal. http://www.chakkaradeep.com/post/SharePoint-2010-e28093-LINQ-for-SharePoint.aspx
ReplyDelete