SharePoint 2010 addresses this through adding an AddItem method for the SPList class. Internally it uses the static SPQuery.TrivialQuery (essentially an empty query*) to add the item to an empty ListItem collection, achieving the same effect as AddItemOptimized():
"Beware of SPList.Items.Add()"
2 Comments -
Great find! I think your optimized method could be pretty useful to add items to a big list.
I hope they fix this in Sharepoint 2010.
Tuesday, September 22, 2009 2:01:00 AM
SharePoint 2010 addresses this through adding an AddItem method for the SPList class. Internally it uses the static SPQuery.TrivialQuery (essentially an empty query*) to add the item to an empty ListItem collection, achieving the same effect as AddItemOptimized():
*TrivialQuery code:
internal static SPQuery TrivialQuery
{
get
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">-1</Value></Eq></Where>";
query.ViewFields = "<FieldRef Name=\"ID\"/>";
return query;
}
}
Monday, July 19, 2010 3:43:00 PM