Category Archives: Obejct Model

“Handle with Care “ – SharePoint Lists with Large lists

Here are few key things to remember when implementing SharePoint applications with high volumes of data.

    1. Never try to override List View Threshold. Keep it to 5000 as it is by default.
    2. Try avoiding increase of “List View Lookup Threshold”, keep it as 8
    3. Apply indexes to relevant columns. Be mindful about the content of column before adding indexes
    4. Use out of the box webparts as much as possible. Utilize parametrized list view webparts, connected webparts etc to achieve advance filtered listings
    5. Make sure to use indexed columns as much as possible in CAML queries
    6. Make sure to prioritized CAML query filters depending up on number of items filter out by each clause
    7. Avoid using People fields for CAML query filtering (anyway those are not index-able)
    8. Don’t rely on lookup columns heavily.
    9. Make sure you filter only the required set of list items
    10. Try using SPListItem.GetItemById whenever an Items being retrieved
    11. Avoid using SPQuery to make queries, instead user ContentIterator so that there will be less locks in DB
    12. If required, use caching(possibly ASP.Net Cache) when custom code is being used
    13. Off load processing from server as much as possible

 

      Some more tips by Amit Phatak at http://navigatingsharepoint.blogspot.com/2010/08/sharepoint-2010-handling-large-splists.html
Advertisements

Handle with care, Json Serialization when SharePoint Object Model’s Objects in the code

My team went crazy with the generic error message that they were getting while trying to Serialize an object created of some POCO. One of them even lost good whole day trying to troubleshoot what exactly is the issue.

The serializer is one of the best in business for .Net , the Newtonsoft.Json.JsonConvert.

And the error message they were getting is

“An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll”

which hardly express any means of the cause. This error message is thrown when following piece of code is getting executed.

 JsonConvert.SerializeObject(MyEntity, Newtonsoft.Json.Formatting.Indented);

Finally I figured it out that one of the newly added Properties of MyEntity’s class causing the issue.

The newly added Property is of SPUser field.  So the entity class looked like following,

   public class MyEntity

{

public string Name { get; set; }

public string LoginName { get; set; }

public SPUser User { get; set; }

}

So the issue with the Serializer unable to serialize the instance of SPUser. The when I checked the serializer is unable to serialize SPFieldUserValue and SPFieldUserValueCollection as well.

Workaround :

Anyway fortunately I did not want this field necessarily be in the Json that I was getting.

So I decorated each of those fields with [JsonIgnoreAttribute] attribute. Doing that I had to import the Newtonsoft.Json with using directive. That made my entity class look like ,

   public class MyEntity

{

public string Name { get; set; }

public string LoginName { get; set; }

[JsonIgnoreAttribute]

public SPUser User { get; set; }

}

In conclusion, even if you use more improved serializer like Newtonsoft.json, you should be very careful about what you are trying to serialize and desterilize especially when you are dealing with SharePoint Object model’s classes.