I am trying to get the items from a Sharepoint list with no luck. My code resembles the following:
using (DataContext data = new DataContext(SPContext.Current.Web.Url))
{
var typeList= data.GetList<MyType>("SomeList");
var ty = from t in typeList
orderby t.SortOrder
select t;
//this causes the exception
var aList = ty.ToList();
}
Whenever I try to iterate over the items in a loop, or call ToList() on the result of the query, I get this exception:
An exception of type 'System.NullReferenceException' occurred in Microsoft.SharePoint.Linq.dll but was not handled in user code Additional information: Object reference not set to an instance of an object. occurred
I'm at a loss. In .Net, I can go things like this:
var something = myList.OrderBy(m => m.SortOrder).ToList();
How do I do something similar in Sharepoint?