Data returned if GetItems if query did not match

272 views Asked by At

This is really a simple question. What does GetItems method return if SPQueryobject did not find any match? if i call the update method, if it did find anything. Will it add it?

I'm at the point of investigating a bug and I still don't have a environment for me to test and I'm new to SharePoint development so guys, please be gentle :D

1

There are 1 answers

0
Stefan On

The item will be added anyway. It doesn't matter if there are any items in the SPListItemCollection.

SPList.AddItem() uses this behavior to avoid loading all of the items in the list. One could write:

SPList list = ...
list.Items.Add(); 

This loads all the items in the list, which might be slow for large item sets.

SPList.AddItem() retrieves the SPListItemCollection by executing a CAML query that returns no items (ID == -1) and calls then the Add method.